diff --git a/services/api/sources/__pycache__/connectors.cpython-314.pyc b/services/api/sources/__pycache__/connectors.cpython-314.pyc index 962d4a2..c93da6d 100644 Binary files a/services/api/sources/__pycache__/connectors.cpython-314.pyc and b/services/api/sources/__pycache__/connectors.cpython-314.pyc differ diff --git a/services/api/sources/connectors.py b/services/api/sources/connectors.py index f547169..4c11bf4 100644 --- a/services/api/sources/connectors.py +++ b/services/api/sources/connectors.py @@ -139,17 +139,78 @@ async def companies_house_by_number(number: str) -> CompanyResult | None: return res -# Registries that require verified terms / keys before bulk use. -# Implement as official-API connectors only; never bypass. Until wired they -# return level-0 so the field is delivered honestly as "ej tillgänglig". -async def prh_by_businessid(business_id: str) -> CompanyResult | None: # FI — VERIFY - return CompanyResult(org_nr=business_id, market="FI", source="prh", - provenance=[Provenance("name", "prh", 0.0, 0, _today())]) +# ── PRH avoindata (FI) — open API (CC-BY). VERIFY terms. ──────────────────── +async def prh_by_businessid(business_id: str) -> CompanyResult | None: + url = f"https://avoindata.prh.fi/opendata-ytj-api/v3/companies?businessId={business_id}" + async with _client() as c: + r = await c.get(url) + if r.status_code != 200: + return None + items = r.json().get("companies") or r.json().get("results") or [] + if not items: + return None + d = items[0] + names = d.get("names") or [] + name = names[0].get("name") if names else d.get("name") + res = CompanyResult(org_nr=business_id, market="FI", name=name, status=d.get("status"), source="prh") + if name: + res.provenance.append(Provenance("name", "prh", 0.95, 3, _today())) + return res -async def cvr_by_number(cvr: str) -> CompanyResult | None: # DK — VERIFY (Virk terms) - return CompanyResult(org_nr=cvr, market="DK", source="cvr", - provenance=[Provenance("name", "cvr", 0.0, 0, _today())]) +# ── CVR (DK) via cvrapi.dk — free for low volume (descriptive UA). VERIFY. ─── +async def cvr_by_number(cvr: str) -> CompanyResult | None: + url = f"https://cvrapi.dk/api?search={cvr}&country=dk" + async with _client() as c: + r = await c.get(url) + if r.status_code != 200: + return None + d = r.json() + if not d.get("name"): + return None + res = CompanyResult( + org_nr=cvr, market="DK", name=d.get("name"), + status="ceased" if d.get("enddate") else "active", + address={"raw": d.get("address")}, source="cvr", + ) + f = _today() + res.provenance += [Provenance("name", "cvr", 0.93, 3, f), Provenance("address", "cvr", 0.9, 2, f)] + return res + + +# ── RDW (NL) open vehicle data — Socrata. Technical/fleet only, no owner PII. ─ +async def rdw_vehicle(kenteken: str) -> dict[str, Any] | None: + plate = kenteken.upper().replace("-", "").replace(" ", "") + url = f"https://opendata.rdw.nl/resource/m9d7-ebf2.json?kenteken={plate}" + async with _client() as c: + r = await c.get(url) + if r.status_code != 200: + return None + arr = r.json() + if not arr: + return None + d = arr[0] + return { + "reg_plate": kenteken, "market": "NL", + "make": d.get("merk"), "model": d.get("handelsbenaming"), + "year": (d.get("datum_eerste_toelating") or "")[:4] or None, + "source": "rdw", + "provenance": [{"field": "make", "source_id": "rdw", "confidence": 0.9, "level": 3, "freshness": _today()}], + } + + +# ── OpenSanctions screening — search API. VERIFY commercial terms / key. ───── +async def opensanctions_screen(name: str) -> dict[str, Any]: + url = "https://api.opensanctions.org/search/default" + async with _client() as c: + r = await c.get(url, params={"q": name, "limit": 5}) + if r.status_code != 200: + return {"matches": [], "source": "opensanctions"} + results = r.json().get("results", []) + return { + "source": "opensanctions", + "matches": [{"name": x.get("caption"), "score": x.get("score"), "schema": x.get("schema")} for x in results], + } CONNECTORS = { diff --git a/services/api/workers/__pycache__/pipeline.cpython-314.pyc b/services/api/workers/__pycache__/pipeline.cpython-314.pyc index 64df536..77e79ea 100644 Binary files a/services/api/workers/__pycache__/pipeline.cpython-314.pyc and b/services/api/workers/__pycache__/pipeline.cpython-314.pyc differ diff --git a/services/api/workers/pipeline.py b/services/api/workers/pipeline.py index 8b4f131..4e279e9 100644 --- a/services/api/workers/pipeline.py +++ b/services/api/workers/pipeline.py @@ -13,7 +13,9 @@ from sources.connectors import ( CompanyResult, brreg_by_orgnr, companies_house_by_number, + cvr_by_number, gleif_by_lei, + prh_by_businessid, ) from workers.adaptive_router import plan_for_market @@ -31,6 +33,10 @@ async def _fetch(source_id: str, key: str) -> CompanyResult | None: return await brreg_by_orgnr(key) if source_id == "companies_house": return await companies_house_by_number(key) + if source_id == "prh": + return await prh_by_businessid(key) + if source_id == "cvr": + return await cvr_by_number(key) return None