Source code for cadrumo.application.live.notification_ports
"""Application-owned ports and DTOs for live notifications.The live notification service consumes these structural ports. Concrete sede,PDF/parser and persistence adapters are assembled by an entrypoint instead ofbeing imported by the application service."""from__future__importannotationsfromcollections.abcimportAwaitable,Callablefromdataclassesimportdataclassfromdatetimeimportdate,datetimefromenumimportStrEnumfromtypingimportAny,Literal,ProtocolfrompydanticimportBaseModel,Fieldfrom...core.configimportSettingsfrom...core.identity.aeat_certificadoimportAeatCertificadoIdfrom...core.modelsimportSTRICT_FROZEN_CONFIGfrom...domain.notifications.sancionimportSancionLiquidacionfrom..auth.session_typesimportAeatSessionfrom.snapshot_baseimportSnapshotRepository
[docs]classNotificationType(StrEnum):"""Application-owned classification of one remote notification row."""NOTIFICACION="notificacion"COMUNICACION="comunicacion"PENDIENTE="pendiente"UNKNOWN="unknown"
[docs]classRemoteNotification(BaseModel):"""Application DTO for one observed AEAT notification row. The Sede adapter owns its scraped DTO and translates it to this record before the row enters application orchestration or encrypted custody. """model_config=STRICT_FROZEN_CONFIGcertificado_id:AeatCertificadoIdtipo:NotificationTypeValueconcepto:str=Field(default="",max_length=256)titular_nif:str=Field(min_length=4,max_length=32)titular_nombre:str=Field(max_length=256)destinatario_nif:str=Field(max_length=32)destinatario_nombre:str=Field(max_length=256)fecha_emision:datefecha_notificacion:date|None=Nonemodo_notificacion:str|None=Field(default=None,max_length=64)leida:bool|None=Nonesource_url:str=Field(min_length=1)mode:Literal["read"]="read"
[docs]classNotificationsSnapshot(BaseModel):"""Application DTO for one read-only notifications query result."""model_config=STRICT_FROZEN_CONFIGrows:tuple[RemoteNotification,...]captured_at:datetimesource_url:str=Field(min_length=1)mode:Literal["read"]="read"
[docs]classNotificationSnapshotQueryProtocol(Protocol):"""Read the authenticated notification surface and translate its result."""
[docs]asyncdeffetch(self,session:AeatSession,*,settings:Settings)->NotificationsSnapshot:"""Return one application-owned notifications snapshot."""...
[docs]@dataclass(frozen=True,slots=True)classNotificationsPorts:"""Required live-query and bucket-persistence capabilities for notifications."""snapshot_query:NotificationSnapshotQueryProtocolsnapshot_repository_factory:NotificationSnapshotRepositoryFactory
[docs]classNotificationRowProtocol(Protocol):"""The notification-row facts needed by the custody use case."""@propertydefcertificado_id(self)->AeatCertificadoId:"""Execute this public contract operation."""...@propertydeftipo(self)->str:"""Execute this public contract operation."""...@propertydeffecha_emision(self)->date:"""Execute this public contract operation."""...@propertydefleida(self)->bool|None:"""Execute this public contract operation."""...
[docs]classNotificationDocumentProtocol(Protocol):"""The in-memory document facts needed by the custody use case."""@propertydefcertificado_id(self)->AeatCertificadoId:"""Execute this public contract operation."""...@propertydefpdf_bytes(self)->bytes:"""Execute this public contract operation."""...@propertydefpdf_sha256(self)->str:"""Execute this public contract operation."""...@propertydefsource_url(self)->object:"""Execute this public contract operation."""...
[docs]classNotificationDocumentReaderProtocol(Protocol):"""Read document bytes into a domain reading or an explicit refusal."""
[docs]defread(self,document:NotificationDocumentProtocol,)->tuple[SancionLiquidacion|None,str|None]:"""Execute this public contract operation."""...
# The adapter signatures carry concrete session/row types. ``...`` keeps the# application port independent of those adapter classes while still requiring# the callable shape at runtime.NotificationContentGuard=Callable[...,None]NotificationDocumentFetcher=Callable[...,Awaitable[NotificationDocumentProtocol]]__all__=["NotificationContentGuard","NotificationDocumentFetcher","NotificationDocumentProtocol","NotificationDocumentReaderProtocol","NotificationRowProtocol","NotificationSnapshotQueryProtocol","NotificationSnapshotRepositoryFactory","NotificationType","NotificationTypeValue","NotificationsPorts","NotificationsSnapshot","RemoteNotification",]