From 3fc093cbc14867e406dc91c7e7db727c8798dfae Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:28:15 +0200 Subject: [PATCH 1/7] fix: enrichment response case-insensitive status, missing fields --- src/tic/enrichment.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/tic/enrichment.py b/src/tic/enrichment.py index 8fb1bc2..21c3019 100644 --- a/src/tic/enrichment.py +++ b/src/tic/enrichment.py @@ -2,8 +2,9 @@ from datetime import datetime from enum import StrEnum +from typing import Annotated -from pydantic import BaseModel +from pydantic import BaseModel, BeforeValidator from .data import SigningAuthorityAnalysis from .models import CamelModel @@ -31,6 +32,13 @@ class EnrichmentType(StrEnum): FULL = "Full" +def _normalize_enrichment_status(v: object) -> object: + if isinstance(v, str): + mapping = {s.lower(): s for s in EnrichmentStatus} + return mapping.get(v.lower(), v) + return v + + # --------------------------------------------------------------------------- # Request / Response models # --------------------------------------------------------------------------- @@ -39,9 +47,10 @@ class EnrichmentType(StrEnum): class EnrichmentResponse(CamelModel): enrichment_id: str session_id: str - status: EnrichmentStatus + status: Annotated[EnrichmentStatus, BeforeValidator(_normalize_enrichment_status)] requested_types: list[str] - completed_types: list[str] + completed_types: list[str] = [] + error: str | None = None secure_url: str | None = None secure_url_expires_at_utc: datetime | None = None @@ -52,6 +61,11 @@ class EnrichmentTypeInfo(CamelModel): enabled: bool +class EnrichmentTypesResponse(CamelModel): + types: list[EnrichmentTypeInfo] = [] + enabled: bool = False + + # --------------------------------------------------------------------------- # SPAR data (field names match SPAR/Navet column names — NOT camelCase) # --------------------------------------------------------------------------- From 5078a3b3fa2b26212e008741f8a2e2a08b25fd9f Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:28:26 +0200 Subject: [PATCH 2/7] fix: models match real TIC API responses --- src/tic/models.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/tic/models.py b/src/tic/models.py index b6c9bf5..3f332c3 100644 --- a/src/tic/models.py +++ b/src/tic/models.py @@ -56,6 +56,8 @@ class User(CamelModel): given_name: str surname: str name: str | None = None + external_subject_id: str | None = None + provider: str | None = None class Signature(CamelModel): @@ -88,12 +90,20 @@ class SessionStatus(CamelModel): class QRCodeResult(CamelModel): qr_data: str valid_for_seconds: int + order_age: int | None = None class ExtendResult(CamelModel): - success: bool + extended: bool error: str | None = None new_expires_at: datetime | None = None + session_expires_in_seconds: int | None = None + + +class UsageLimits(CamelModel): + authentications_per_month: int | None = None + signings_per_month: int | None = None + enrichments_per_month: int | None = None class UsageStats(CamelModel): @@ -106,6 +116,9 @@ class UsageStats(CamelModel): signings_started: int | None = None signings_completed: int | None = None signings_failed: int | None = None + enrichments_requested: int | None = None + enrichments_delivered: int | None = None + limits: UsageLimits | None = None # --- SignalR hub event models --- @@ -215,23 +228,42 @@ class EnrichmentFailedData(CamelModel): class IpInfo(CamelModel): ip_address: str country_code: str | None = None + country_name: str | None = None + isp: str | None = None + usage_type: str | None = None is_tor: bool = False is_likely_vpn: bool = False + confidence_score: int | None = None class RiskAssessment(CamelModel): level: str score: int + indicators: list[str] = [] class IpIntelligence(CamelModel): initiating_ip: IpInfo | None = None - risk: RiskAssessment | None = None + device_ip: IpInfo | None = None + overall_risk: RiskAssessment | None = None + enriched_at_utc: datetime | None = None # --- Messages --- +class HintCodeMapping(CamelModel): + rfa: str + variants: list[str] = [] + + +class MessagesResponse(CamelModel): + language: str + messages: dict[str, str] + hint_code_mapping: dict[str, HintCodeMapping] = {} + + +# Deprecated: use MessagesResponse instead class LocalizedMessage(CamelModel): hint_code: str message: str From 8983f372eb858a36fca563c4c102266b270426cc Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:28:36 +0200 Subject: [PATCH 3/7] fix: client return types for messages and enrichment types --- src/tic/client.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/tic/client.py b/src/tic/client.py index afe9a77..f85c9d8 100644 --- a/src/tic/client.py +++ b/src/tic/client.py @@ -15,6 +15,7 @@ EnrichmentData, EnrichmentResponse, EnrichmentTypeInfo, + EnrichmentTypesResponse, ) from .exceptions import TicAPIError from .models import ( @@ -22,7 +23,7 @@ AuthStartRequest, CollectResult, ExtendResult, - LocalizedMessage, + MessagesResponse, QRCodeResult, SessionStatus, SignStartRequest, @@ -222,13 +223,11 @@ async def get_usage(self, year: int, month: int) -> UsageStats: # --- Messages --- - async def get_messages(self, language: str = "sv") -> list[LocalizedMessage]: + async def get_messages(self, language: str = "sv") -> MessagesResponse: data = await self._request( "GET", "/api/v1/messages", params={"language": language} ) - if isinstance(data, list): - return [LocalizedMessage.from_api(m) for m in data] - return [LocalizedMessage.from_api(m) for m in data.get("messages", [])] + return MessagesResponse.from_api(data) # --- Enrichment --- @@ -252,10 +251,9 @@ async def get_enrichment_status(self, enrichment_id: str) -> EnrichmentResponse: data = await self._request("GET", f"/api/v1/enrichment/{enrichment_id}/status") return EnrichmentResponse.from_api(data) - async def get_enrichment_types(self) -> list[EnrichmentTypeInfo]: + async def get_enrichment_types(self) -> EnrichmentTypesResponse: data = await self._request("GET", "/api/v1/enrichment/types") - items = data if isinstance(data, list) else data.get("types", []) - return [EnrichmentTypeInfo.from_api(t) for t in items] + return EnrichmentTypesResponse.from_api(data) async def get_enrichment_data(self, token: str) -> EnrichmentData: data = await self._request("GET", f"/api/v1/enrichment/data/{token}") From f0b4d8849dfa6dae1bc05511c375841cb06ea64e Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:28:55 +0200 Subject: [PATCH 4/7] chore: bump version to 0.2.0, update exports --- pyproject.toml | 2 +- src/tic/__init__.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e5a58f9..66faf9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "tic-identity-python" -version = "0.1.0" +version = "0.2.0" description = "Unofficial Python client for TIC Identity (id.tic.io) — BankID authentication and digital signing" readme = "README.md" requires-python = ">=3.11" diff --git a/src/tic/__init__.py b/src/tic/__init__.py index d2847c0..4e3a036 100644 --- a/src/tic/__init__.py +++ b/src/tic/__init__.py @@ -1,6 +1,6 @@ """TIC Identity Python client — BankID authentication and digital signing via id.tic.io.""" -__version__ = "0.1.0" +__version__ = "0.2.0" from .client import RateLimitInfo, TicClient from .constants import ( @@ -26,6 +26,7 @@ EnrichmentStatus, EnrichmentType, EnrichmentTypeInfo, + EnrichmentTypesResponse, SparData, ) from .exceptions import TicAPIError, TicError, TicHubError, TicWebhookError @@ -42,9 +43,11 @@ EnrichmentFailedData, ExtendResult, Failed, + HintCodeMapping, IpInfo, IpIntelligence, LocalizedMessage, + MessagesResponse, OrderRegenerated, QRCodeResult, RiskAssessment, @@ -55,6 +58,7 @@ StatusChanged, SubscribeResponse, TimeoutWarning, + UsageLimits, UsageStats, User, WebhookPayload, @@ -89,9 +93,12 @@ "QRCodeResult", "SessionStatus", "SignStartRequest", + "UsageLimits", "UsageStats", "User", "Signature", + "HintCodeMapping", + "MessagesResponse", "LocalizedMessage", # Hub models "AuthStatusResponse", @@ -124,6 +131,7 @@ "EnrichmentStatus", "EnrichmentType", "EnrichmentTypeInfo", + "EnrichmentTypesResponse", "SparData", # Data Verification "CompanyCreditData", From 1bd0ebe1d8ee56364234609757c76b1e92255eb5 Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:31:30 +0200 Subject: [PATCH 5/7] fix: remove unused EnrichmentTypeInfo import --- src/tic/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tic/client.py b/src/tic/client.py index f85c9d8..ad76ea0 100644 --- a/src/tic/client.py +++ b/src/tic/client.py @@ -14,7 +14,6 @@ from .enrichment import ( EnrichmentData, EnrichmentResponse, - EnrichmentTypeInfo, EnrichmentTypesResponse, ) from .exceptions import TicAPIError From cc0b7a1875ecde648164e6aa8f66a27a6df61382 Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:33:38 +0200 Subject: [PATCH 6/7] fix: update tests to match corrected field names --- tests/test_client.py | 5 +++-- tests/test_models.py | 36 +++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index fc84b33..5e57ba3 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -259,14 +259,15 @@ async def test_extend_success( return_value=httpx.Response( 200, json={ - "success": True, + "extended": True, "newExpiresAt": "2026-06-15T12:10:00Z", + "sessionExpiresInSeconds": 586, }, ), ) ext = await client.extend("sess-100") assert isinstance(ext, ExtendResult) - assert ext.success is True + assert ext.extended is True assert ext.new_expires_at is not None diff --git a/tests/test_models.py b/tests/test_models.py index 03f2d0d..e77d503 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -309,18 +309,20 @@ def test_from_api(self): class TestExtendResult: def test_from_api_success(self): data = { - "success": True, + "extended": True, "newExpiresAt": "2026-06-15T12:10:00Z", + "sessionExpiresInSeconds": 586, } ext = ExtendResult.from_api(data) - assert ext.success is True + assert ext.extended is True assert ext.error is None assert ext.new_expires_at is not None + assert ext.session_expires_in_seconds == 586 def test_from_api_failure(self): - data = {"success": False, "error": "Session cannot be extended"} + data = {"extended": False, "error": "Session cannot be extended"} ext = ExtendResult.from_api(data) - assert ext.success is False + assert ext.extended is False assert ext.error == "Session cannot be extended" assert ext.new_expires_at is None @@ -419,19 +421,27 @@ def test_from_api_full(self): "isTor": False, "isLikelyVpn": False, }, - "risk": {"level": "low", "score": 10}, + "deviceIp": { + "ipAddress": "5.6.7.8", + "countryCode": "SE", + "isTor": False, + "isLikelyVpn": False, + }, + "overallRisk": {"level": "low", "score": 10, "indicators": []}, } intel = IpIntelligence.from_api(data) assert intel.initiating_ip is not None assert intel.initiating_ip.ip_address == "1.2.3.4" - assert intel.risk is not None - assert intel.risk.level == "low" - assert intel.risk.score == 10 + assert intel.device_ip is not None + assert intel.device_ip.ip_address == "5.6.7.8" + assert intel.overall_risk is not None + assert intel.overall_risk.level == "low" + assert intel.overall_risk.score == 10 def test_from_api_none_fields(self): intel = IpIntelligence.from_api({}) assert intel.initiating_ip is None - assert intel.risk is None + assert intel.overall_risk is None # --------------------------------------------------------------------------- @@ -469,13 +479,13 @@ def test_from_api_with_ip_intelligence(self): }, "ipIntelligence": { "initiatingIp": {"ipAddress": "203.0.113.42", "countryCode": "SE"}, - "risk": {"level": "low", "score": 5}, + "overallRisk": {"level": "low", "score": 5, "indicators": []}, }, } result = AuthCompletedData.from_api(data) assert result.ip_intelligence is not None assert result.ip_intelligence.initiating_ip.ip_address == "203.0.113.42" - assert result.ip_intelligence.risk.level == "low" + assert result.ip_intelligence.overall_risk.level == "low" # --------------------------------------------------------------------------- @@ -513,12 +523,12 @@ def test_from_api_with_ip_intelligence(self): "signature": {"value": "sig-val", "ocspResponse": "ocsp-val"}, "ipIntelligence": { "initiatingIp": {"ipAddress": "10.0.0.1"}, - "risk": {"level": "high", "score": 85}, + "overallRisk": {"level": "high", "score": 85, "indicators": []}, }, } result = SignCompletedData.from_api(data) assert result.ip_intelligence is not None - assert result.ip_intelligence.risk.score == 85 + assert result.ip_intelligence.overall_risk.score == 85 # --------------------------------------------------------------------------- From b07178a59fb1a8f2ee3cd2f3096c3d57080426fb Mon Sep 17 00:00:00 2001 From: Liam Lenholm Date: Wed, 22 Apr 2026 20:38:20 +0200 Subject: [PATCH 7/7] fix: VAT alias casing, webhook expiresAtUtc field name --- src/tic/data.py | 4 +++- src/tic/models.py | 2 +- tests/test_data.py | 4 ++-- tests/test_models.py | 6 +++--- uv.lock | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/tic/data.py b/src/tic/data.py index 196660e..409048c 100644 --- a/src/tic/data.py +++ b/src/tic/data.py @@ -3,6 +3,8 @@ from datetime import datetime +from pydantic import Field + from .models import CamelModel @@ -116,7 +118,7 @@ class CompanyLookupData(CamelModel): activity_status: str # HasNeverBeenActive | IsActive | IsNoLongerActive | Unknown last_status: LastStatus | None = None registered_address: Address | None = None - is_registered_for_vat: bool | None = None + is_registered_for_vat: bool | None = Field(None, alias="isRegisteredForVAT") is_registered_for_f_tax: bool | None = None is_registered_for_payroll: bool | None = None sni_codes_2025: list[SniCode] | None = None diff --git a/src/tic/models.py b/src/tic/models.py index 3f332c3..aa31900 100644 --- a/src/tic/models.py +++ b/src/tic/models.py @@ -210,7 +210,7 @@ class EnrichmentCompletedData(CamelModel): session_id: str status: str secure_url: str - secure_url_expires_at_utc: datetime | None = None + expires_at_utc: datetime | None = None state: str | None = None diff --git a/tests/test_data.py b/tests/test_data.py index 910695e..e4dd8f4 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -47,7 +47,7 @@ def test_from_api_full(self): "city": "Stockholm", "countryCode": "SWE", }, - "isRegisteredForVat": True, + "isRegisteredForVAT": True, "isRegisteredForFTax": True, "isRegisteredForPayroll": True, "sniCodes2025": [ @@ -190,7 +190,7 @@ def test_to_api_produces_camel_case(self): "companyId": 22222, "registrationNumber": "5590000002", "activityStatus": "IsActive", - "isRegisteredForVat": True, + "isRegisteredForVAT": True, }, } resp = CompanyLookupResponse.from_api(data) diff --git a/tests/test_models.py b/tests/test_models.py index e77d503..74005f3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -543,7 +543,7 @@ def test_from_api_full(self): "sessionId": "sess-001", "status": "completed", "secureUrl": "https://id.tic.io/enrichment/data/token-abc", - "secureUrlExpiresAtUtc": "2026-06-15T12:30:00Z", + "expiresAtUtc": "2026-06-15T12:30:00Z", "state": "my-state", } result = EnrichmentCompletedData.from_api(data) @@ -551,7 +551,7 @@ def test_from_api_full(self): assert result.session_id == "sess-001" assert result.secure_url == "https://id.tic.io/enrichment/data/token-abc" assert result.state == "my-state" - assert result.secure_url_expires_at_utc is not None + assert result.expires_at_utc is not None def test_from_api_minimal(self): data = { @@ -562,7 +562,7 @@ def test_from_api_minimal(self): } result = EnrichmentCompletedData.from_api(data) assert result.state is None - assert result.secure_url_expires_at_utc is None + assert result.expires_at_utc is None # --------------------------------------------------------------------------- diff --git a/uv.lock b/uv.lock index 290cca8..c948969 100644 --- a/uv.lock +++ b/uv.lock @@ -309,7 +309,7 @@ wheels = [ [[package]] name = "tic-identity-python" -version = "0.1.0" +version = "0.2.0" source = { editable = "." } dependencies = [ { name = "httpx" },