Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion src/tic/__init__.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -26,6 +26,7 @@
EnrichmentStatus,
EnrichmentType,
EnrichmentTypeInfo,
EnrichmentTypesResponse,
SparData,
)
from .exceptions import TicAPIError, TicError, TicHubError, TicWebhookError
Expand All @@ -42,9 +43,11 @@
EnrichmentFailedData,
ExtendResult,
Failed,
HintCodeMapping,
IpInfo,
IpIntelligence,
LocalizedMessage,
MessagesResponse,
OrderRegenerated,
QRCodeResult,
RiskAssessment,
Expand All @@ -55,6 +58,7 @@
StatusChanged,
SubscribeResponse,
TimeoutWarning,
UsageLimits,
UsageStats,
User,
WebhookPayload,
Expand Down Expand Up @@ -89,9 +93,12 @@
"QRCodeResult",
"SessionStatus",
"SignStartRequest",
"UsageLimits",
"UsageStats",
"User",
"Signature",
"HintCodeMapping",
"MessagesResponse",
"LocalizedMessage",
# Hub models
"AuthStatusResponse",
Expand Down Expand Up @@ -124,6 +131,7 @@
"EnrichmentStatus",
"EnrichmentType",
"EnrichmentTypeInfo",
"EnrichmentTypesResponse",
"SparData",
# Data Verification
"CompanyCreditData",
Expand Down
15 changes: 6 additions & 9 deletions src/tic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from .enrichment import (
EnrichmentData,
EnrichmentResponse,
EnrichmentTypeInfo,
EnrichmentTypesResponse,
)
from .exceptions import TicAPIError
from .models import (
AuthSession,
AuthStartRequest,
CollectResult,
ExtendResult,
LocalizedMessage,
MessagesResponse,
QRCodeResult,
SessionStatus,
SignStartRequest,
Expand Down Expand Up @@ -222,13 +222,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 ---

Expand All @@ -252,10 +250,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}")
Expand Down
4 changes: 3 additions & 1 deletion src/tic/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime


from pydantic import Field

from .models import CamelModel


Expand Down Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions src/tic/enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand All @@ -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

Expand All @@ -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)
# ---------------------------------------------------------------------------
Expand Down
38 changes: 35 additions & 3 deletions src/tic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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 ---
Expand Down Expand Up @@ -197,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


Expand All @@ -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
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_from_api_full(self):
"city": "Stockholm",
"countryCode": "SWE",
},
"isRegisteredForVat": True,
"isRegisteredForVAT": True,
"isRegisteredForFTax": True,
"isRegisteredForPayroll": True,
"sniCodes2025": [
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading