latinfo 0.18.1 → 0.19.1

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/dist/sdk.d.ts CHANGED
@@ -137,8 +137,10 @@ declare class Country {
137
137
  protected cfg: SourceConfig;
138
138
  private mphfIndex;
139
139
  constructor(request: <T>(path: string) => Promise<T>, rawRequest: (path: string) => Promise<Response>, cfg: SourceConfig);
140
- /** Download and load MPHF index from API. Call once — enables offline search. */
140
+ /** Download and load MPHF index. Call once — enables offline search. */
141
141
  loadIndex(): Promise<void>;
142
+ /** Check if there is a newer MPHF and update in background. Safe to call on every app open. */
143
+ refreshIndex(): void;
142
144
  /** Load MPHF index from a pre-fetched buffer (e.g., bundled in APK). */
143
145
  loadIndexFromBuffer(buf: ArrayBuffer): void;
144
146
  /** Whether MPHF index is loaded (offline search available). */
package/dist/sdk.js CHANGED
@@ -4,8 +4,8 @@ exports.Latinfo = void 0;
4
4
  const mphf_runtime_1 = require("./mphf-runtime");
5
5
  const DEFAULT_API_URL = 'https://api.latinfo.dev';
6
6
  const SOURCES = {
7
- pe: { prefix: 'pe', baseName: 'pe-sunat-padron', idName: 'ruc', idLength: 11, nameField: 'razon_social', statusField: 'estado' },
8
- co: { prefix: 'co', baseName: 'co-rues', idName: 'nit', idLength: 10, nameField: 'razon_social', statusField: 'estado_matricula' },
7
+ pe: { prefix: 'pe/sunat/padron', baseName: 'pe-sunat-padron', idName: 'ruc', idLength: 11, nameField: 'razon_social', statusField: 'estado' },
8
+ co: { prefix: 'co/rues/registry', baseName: 'co-rues-registry', idName: 'nit', idLength: 10, nameField: 'razon_social', statusField: 'estado_matricula' },
9
9
  };
10
10
  // --- Country class ---
11
11
  class Country {
@@ -18,24 +18,19 @@ class Country {
18
18
  this.rawRequest = rawRequest;
19
19
  this.cfg = cfg;
20
20
  }
21
- /** Download and load MPHF index from API. Call once — enables offline search. */
21
+ /** Download and load MPHF index. Call once — enables offline search. */
22
22
  async loadIndex() {
23
- const res = await this.rawRequest(`/${this.cfg.prefix}/dictionary`);
23
+ const res = await this.rawRequest(`/${this.cfg.prefix}/mphf`);
24
24
  if (!res.ok)
25
25
  throw new Error(`Failed to download MPHF index: ${res.status}`);
26
- // The dictionary endpoint returns .idx. We need .mphf.
27
- // Use a dedicated mphf endpoint or construct URL.
28
- const mphfRes = await this.rawRequest(`/${this.cfg.prefix}/mphf`);
29
- if (!mphfRes.ok) {
30
- // Fallback: try R2 direct
31
- const cdnUrl = `https://data.latinfo.dev/${this.cfg.baseName}-search.mphf`;
32
- const cdnRes = await fetch(cdnUrl);
33
- if (!cdnRes.ok)
34
- throw new Error('MPHF index not available');
35
- this.mphfIndex = (0, mphf_runtime_1.deserializeMphfIndex)(await cdnRes.arrayBuffer());
36
- return;
37
- }
38
- this.mphfIndex = (0, mphf_runtime_1.deserializeMphfIndex)(await mphfRes.arrayBuffer());
26
+ this.mphfIndex = (0, mphf_runtime_1.deserializeMphfIndex)(await res.arrayBuffer());
27
+ }
28
+ /** Check if there is a newer MPHF and update in background. Safe to call on every app open. */
29
+ refreshIndex() {
30
+ this.rawRequest(`/${this.cfg.prefix}/mphf`).then(async (res) => {
31
+ if (res.ok)
32
+ this.mphfIndex = (0, mphf_runtime_1.deserializeMphfIndex)(await res.arrayBuffer());
33
+ }).catch(() => { });
39
34
  }
40
35
  /** Load MPHF index from a pre-fetched buffer (e.g., bundled in APK). */
41
36
  loadIndexFromBuffer(buf) {
@@ -71,13 +66,16 @@ class Country {
71
66
  return [];
72
67
  resolved.push(r);
73
68
  }
74
- // Fetch posting lists from API
69
+ // Fetch posting lists directly from R2 CDN (no Worker, no tunnel)
75
70
  const tokenPostings = [];
76
71
  for (const r of resolved) {
77
72
  const lists = await Promise.all(r.entries.map(async (entry) => {
78
73
  const byteLen = Math.min(entry.count, 50000) * idx.entrySize;
79
- const res = await this.rawRequest(`/${this.cfg.prefix}/posting-raw/${entry.shard}?offset=${entry.offset}&length=${byteLen}`);
80
- if (!res.ok)
74
+ const cdnUrl = `https://data.latinfo.dev/${this.cfg.baseName}-search-${entry.shard}.dat`;
75
+ const res = await fetch(cdnUrl, {
76
+ headers: { Range: `bytes=${entry.offset}-${entry.offset + byteLen - 1}` },
77
+ });
78
+ if (!res.ok && res.status !== 206)
81
79
  return [];
82
80
  const buf = await res.arrayBuffer();
83
81
  return (0, mphf_runtime_1.parseV2PostingList)(buf, this.cfg.idLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "latinfo",
3
- "version": "0.18.1",
3
+ "version": "0.19.1",
4
4
  "description": "Tax registry & procurement API for Latin America. Query RUC, DNI, NIT, licitaciones from Peru & Colombia. Offline MPHF search, full OCDS data, updated daily.",
5
5
  "homepage": "https://latinfo.dev",
6
6
  "repository": {