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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ jobs:
- run: uv run ruff check src/ tests/
- run: uv run ruff format --check src/ tests/

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- run: uv sync --extra dev
- run: uv run mypy src/

test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -28,3 +36,14 @@ jobs:
python-version: ${{ matrix.python-version }}
- run: uv sync --extra dev
- run: uv run pytest tests/ -q

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- run: uv build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish to PyPI

on:
release:
types: [published]

permissions:
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- run: uv build
- uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
.mypy_cache/
.ruff_cache/
.claude/
.coverage
3 changes: 2 additions & 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.2.0"
version = "0.2.1"
description = "Unofficial Python client for TIC Identity (id.tic.io) — BankID authentication and digital signing"
readme = "README.md"
requires-python = ">=3.11"
Expand Down Expand Up @@ -34,6 +34,7 @@ dev = [
"pytest-asyncio>=0.24",
"respx>=0.22",
"ruff>=0.15",
"mypy>=1.15",
]

[project.urls]
Expand Down
32 changes: 32 additions & 0 deletions src/tic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@
WebhookHeader,
)
from .data import (
Address,
BeneficialOwner,
CompanyCreditData,
CompanyCreditResponse,
CompanyLookupData,
CompanyLookupResponse,
EligiblePerson,
LastStatus,
RegisteredOffice,
Representative,
ResponseMetadata,
SigningAuthorityAnalysis,
SigningAuthorityData,
SigningAuthorityResponse,
SigningRule,
SniCode,
)
from .enrichment import (
CompanyRolesData,
EnrichmentData,
EnrichmentResponse,
EnrichmentStatus,
EnrichmentType,
EnrichmentTypeInfo,
EnrichmentTypesResponse,
IncomeData,
IpData,
IpIntelligenceData,
IpOverallRisk,
PropertyOwnershipData,
SparData,
)
from .exceptions import TicAPIError, TicError, TicHubError, TicWebhookError
Expand Down Expand Up @@ -126,18 +142,34 @@
"hosted_login_url",
"parse_callback",
# Enrichment
"CompanyRolesData",
"EnrichmentData",
"EnrichmentResponse",
"EnrichmentStatus",
"EnrichmentType",
"EnrichmentTypeInfo",
"EnrichmentTypesResponse",
"IncomeData",
"IpData",
"IpIntelligenceData",
"IpOverallRisk",
"PropertyOwnershipData",
"SparData",
# Data Verification
"Address",
"BeneficialOwner",
"CompanyCreditData",
"CompanyCreditResponse",
"CompanyLookupData",
"CompanyLookupResponse",
"EligiblePerson",
"LastStatus",
"RegisteredOffice",
"Representative",
"ResponseMetadata",
"SigningAuthorityAnalysis",
"SigningAuthorityData",
"SigningAuthorityResponse",
"SigningRule",
"SniCode",
]
3 changes: 2 additions & 1 deletion src/tic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .enrichment import (
EnrichmentData,
EnrichmentResponse,
EnrichmentType,
EnrichmentTypesResponse,
)
from .exceptions import TicAPIError
Expand Down Expand Up @@ -233,7 +234,7 @@ async def get_messages(self, language: str = "sv") -> MessagesResponse:
async def start_enrichment(
self,
session_id: str,
types: list[str],
types: list[EnrichmentType | str],
*,
webhook_url: str | None = None,
state: str | None = None,
Expand Down
10 changes: 6 additions & 4 deletions src/tic/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,19 @@ class WebhookEvent(StrEnum):


class WebhookHeader(StrEnum):
"""HTTP header names included in TIC Identity webhook requests."""
"""HTTP header names included in TIC Identity webhook requests.

The event type is **not** in a header — it lives in the request
body's ``event`` field. Read it from :attr:`WebhookPayload.event`
after :func:`verify_signature`.
"""

SIGNATURE = "X-Ormeo-Signature"
"""HMAC-SHA256 signature of the request body."""

TIMESTAMP = "X-Ormeo-Timestamp"
"""Unix timestamp when the webhook was sent."""

EVENT = "X-Ormeo-Event"
"""The webhook event type (e.g. ``enrichment.completed``)."""

SESSION_ID = "X-Ormeo-Session-Id"
"""The session ID associated with the webhook."""

Expand Down
95 changes: 85 additions & 10 deletions src/tic/enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,55 @@
from enum import StrEnum
from typing import Annotated

from pydantic import BaseModel, BeforeValidator
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field

from .data import SigningAuthorityAnalysis
from .models import CamelModel


def _csharp_camel(field_name: str) -> str:
"""Match .NET's ``JsonNamingPolicy.CamelCase`` exactly.

The TIC API server is .NET. System.Text.Json serialises property
names by lowercasing the leading run of uppercase letters, but
keeps the last uppercase before a lowercase letter as-is (the
standard Pascal-to-camel acronym rule). Examples observed on the
wire:

* ``Person_IdNummer`` → ``person_IdNummer`` (single upper, then lower)
* ``Folkbokforingsadress_SvenskAdress_CareOf`` → ``folkbokforingsadress_SvenskAdress_CareOf``
* ``AR_DEKL`` → ``ar_DEKL`` (all-upper run followed by underscore)
* ``INK_NRV_AKT_TOT`` → ``ink_NRV_AKT_TOT``
* ``XMLDocument`` → ``xmlDocument`` (acronym rule kicks in at ``D``)

Used for SPAR / Income field aliases — those models keep field
names matching SPAR / Skatteverket column conventions and don't
fit pure snake_case ↔ camelCase translation.
"""
if not field_name or not field_name[0].isupper():
return field_name

chars = list(field_name)
chars[0] = chars[0].lower()

n = len(chars)
# If the next char isn't uppercase, we're done (e.g. "Person...").
if n < 2 or not chars[1].isupper():
return "".join(chars)

# Consecutive uppercase letters at the start: lowercase them, but
# if the next-next char is a lowercase letter, stop one early
# (acronym rule: XMLDocument → xmlDocument, not xmldocument).
i = 1
while i < n and chars[i].isupper():
if i + 1 < n and chars[i + 1].isalpha() and not chars[i + 1].isupper():
break
chars[i] = chars[i].lower()
i += 1

return "".join(chars)


# ---------------------------------------------------------------------------
# Enums
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -72,28 +115,51 @@ class EnrichmentTypesResponse(CamelModel):


class SparData(BaseModel):
model_config = {"populate_by_name": True}
model_config = ConfigDict(
populate_by_name=True,
alias_generator=_csharp_camel,
frozen=True,
)

Person_IdNummer: str | None = None
Person_PersonIdTyp: str | None = None
Person_SenasteAndringSPAR: str | None = None

Skydd_Sekretessmarkering: bool | None = None
Skydd_SkyddadFolkbokforing: bool | None = None
PersonDetaljer_Sekretessmarkering: bool | None = None
# Wire sends lowercase `persondetaljer_*`, not `personDetaljer_*`
PersonDetaljer_Sekretessmarkering: bool | None = Field(
None,
alias="persondetaljer_Sekretessmarkering",
)

Namn_Fornamn: str | None = None
Namn_Mellannamn: str | None = None
Namn_Efternamn: str | None = None
Namn_Aviseringsnamn: str | None = None
Namn_Tilltalsnamn: str | None = None

PersonDetaljer_Kon: str | None = None
PersonDetaljer_Fodelsedatum: str | None = None
PersonDetaljer_Avlidendatum: str | None = None
PersonDetaljer_Avregistreringsdatum: str | None = None
PersonDetaljer_AvregistreringsorsakKod: str | None = None
PersonDetaljer_AvregistreringsorsakBeskrivning: str | None = None
PersonDetaljer_Kon: str | None = Field(None, alias="persondetaljer_Kon")
PersonDetaljer_Fodelsedatum: str | None = Field(
None,
alias="persondetaljer_Fodelsedatum",
)
PersonDetaljer_Avlidendatum: str | None = Field(
None,
alias="persondetaljer_Avlidendatum",
)
PersonDetaljer_Avregistreringsdatum: str | None = Field(
None,
alias="persondetaljer_Avregistreringsdatum",
)
PersonDetaljer_AvregistreringsorsakKod: str | None = Field(
None,
alias="persondetaljer_AvregistreringsorsakKod",
)
PersonDetaljer_AvregistreringsorsakBeskrivning: str | None = Field(
None,
alias="persondetaljer_AvregistreringsorsakBeskrivning",
)

Folkbokforing_FolkbokfordLanKod: str | None = None
Folkbokforing_FolkbokfordKommunKod: str | None = None
Expand Down Expand Up @@ -145,7 +211,11 @@ class PropertyOwnershipData(CamelModel):


class IncomeData(BaseModel):
model_config = {"populate_by_name": True}
model_config = ConfigDict(
populate_by_name=True,
alias_generator=_csharp_camel,
frozen=True,
)

AR_DEKL: int | None = None
INK_TJ: int | None = None
Expand All @@ -171,16 +241,21 @@ class IpData(CamelModel):
country_code: str | None = None
country_name: str | None = None
isp: str | None = None
domain: str | None = None
usage_type: str | None = None
confidence_score: int | None = None
is_tor: bool = False
is_likely_vpn: bool = False
is_whitelisted: bool = False
total_reports: int | None = None
distinct_reporters: int | None = None


class IpOverallRisk(CamelModel):
level: str
score: int
indicators: list[str] = []
requires_review: bool = False


class IpIntelligenceData(CamelModel):
Expand Down
6 changes: 5 additions & 1 deletion src/tic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


class CamelModel(BaseModel):
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
model_config = ConfigDict(
alias_generator=to_camel, populate_by_name=True, frozen=True
)

def to_api(self) -> dict[str, Any]:
return self.model_dump(by_alias=True, exclude_none=True)
Expand Down Expand Up @@ -181,6 +183,8 @@ class AuthStatusResponse(CamelModel):


class WebhookPayload(BaseModel):
model_config = ConfigDict(frozen=True)

event: str
timestamp: datetime
data: dict[str, Any]
Expand Down
1 change: 0 additions & 1 deletion src/tic/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

HEADER_SIGNATURE = WebhookHeader.SIGNATURE
HEADER_TIMESTAMP = WebhookHeader.TIMESTAMP
HEADER_EVENT = WebhookHeader.EVENT
HEADER_SESSION_ID = WebhookHeader.SESSION_ID


Expand Down
13 changes: 11 additions & 2 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,20 @@ class TestWebhookHeader:
def test_values(self):
assert WebhookHeader.SIGNATURE == "X-Ormeo-Signature"
assert WebhookHeader.TIMESTAMP == "X-Ormeo-Timestamp"
assert WebhookHeader.EVENT == "X-Ormeo-Event"
assert WebhookHeader.SESSION_ID == "X-Ormeo-Session-Id"

def test_member_count(self):
assert len(WebhookHeader) == 4
# Only three headers sent on the wire; the event type lives in
# the request body, not a header.
assert len(WebhookHeader) == 3

def test_no_event_header(self):
"""The event type is in the body, not a header.

Read it from :attr:`WebhookPayload.event` after
:func:`verify_signature`.
"""
assert not hasattr(WebhookHeader, "EVENT")

def test_usable_as_dict_key(self):
headers = {
Expand Down
Loading
Loading