aeat.domain.attachments._service module¶
Service-layer helpers over AttachmentStoreProtocol.
Thin orchestration on top of AttachmentStoreProtocol primitives:
ingest a file from disk, build the corresponding Attachment
manifest, persist it, and expose simple read paths for callers that
do not need the full repository API.
- add_attachment(store, *, path, kind, source, source_reference, mime_type, captured_at, bucket_id=None, link_transaction_ids=(), link_invoice_ids=(), metadata=None, notes='')[source]¶
Store attachment bytes from a file and persist the corresponding manifest.
The stored bytes’ SHA-256 doubles as the attachment id so equal files deduplicate naturally.
- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocolfor blob storage and manifest persistence.path (
Path) – Local filesystem path to the bytes being ingested.kind (
AttachmentKind) – LogicalAttachmentKindfor the attachment.source (
AttachmentSource) – OriginatingAttachmentSourcechannel.source_reference (
str) – Caller-supplied opaque reference into the originating system (e.g. invoice number, e-mail UID).mime_type (
str) – MIME type of the attachment bytes.captured_at (
datetime) – Wall-clock timestamp when the bytes were captured upstream.bucket_id (
str|None) – Optional owning profile bucket for the evidence record.link_transaction_ids (
tuple[str,...]) – Optional tuple of transaction ids the attachment evidences.link_invoice_ids (
tuple[str,...]) – Optional tuple of invoice ids the attachment evidences.metadata (
Mapping[str,str] |None) – Optional free-form key/value metadata.notes (
str) – Free-form operator notes; defaults to empty.
- Return type:
- Returns:
The persisted
Attachmentmanifest.
- add_attachment_bytes(store, *, data, kind, source, source_reference, mime_type, captured_at, bucket_id=None, link_transaction_ids=(), link_invoice_ids=(), metadata=None, notes='')[source]¶
Store in-memory attachment bytes and persist the corresponding manifest.
The byte-bearing companion to
add_attachment(): it accepts the already-fetched documentdata(e.g. a Drive download resolved viaadapters.outbound.google.resolve_document_link()) instead of a filesystem path, stores the encrypted blob through the sameput_bytes/write_manifestpath, and records the real SHA-256 and suppliedmime_type. The stored bytes’ SHA-256 is the attachment id, so equal documents deduplicate naturally. There is deliberately no link-only path: an evidence record always carries the document’s encrypted bytes.- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.data (
bytes) – The already-fetched document bytes to encrypt and store.kind (
AttachmentKind) – LogicalAttachmentKind.source (
AttachmentSource) – OriginatingAttachmentSource.source_reference (
str) – The original link / reference recorded as provenance.mime_type (
str) – MIME type of the fetched bytes.captured_at (
datetime) – Wall-clock timestamp when the bytes were captured.bucket_id (
str|None) – Optional owning profile bucket for the evidence record.link_transaction_ids (
tuple[str,...]) – Optional transaction ids the attachment evidences.link_invoice_ids (
tuple[str,...]) – Optional invoice ids the attachment evidences.metadata (
Mapping[str,str] |None) – Optional free-form key/value metadata.notes (
str) – Free-form operator notes; defaults to empty.
- Return type:
- Returns:
The persisted
Attachmentmanifest carrying the realsha256andmime_type.
- load_attachment(store, attachment_id)[source]¶
Load one attachment manifest from the store.
- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.attachment_id (
str) – SHA-256 of the attachment bytes.
- Return type:
- Returns:
The
Attachmentmanifest forattachment_id.
- link_attachment_invoice(store, *, attachment_id, invoice_id)[source]¶
Append
invoice_idto an already-persisted attachment’slinked_invoice_ids.Closes the provenance loop the other direction from
add_attachment(_bytes)’slink_invoice_idsparameter: that parameter can only be populated for an invoice that already exists before the evidence is captured, but the evidence-confirmation flow mints theInvoiceafter the attachment is already stored. This helper re-persists the same manifest (attachment id and bytes unchanged) through the sameAttachmentStoreProtocol.write_manifest()write path (composition-service-no-parallel-write-path), withinvoice_idappended.Idempotent by construction:
Attachment’slinked_invoice_idsvalidator deduplicates and preserves first-seen order, so calling this twice with the sameinvoice_idis a no-op – the manifest’s byte content after the second call is identical to after the first (a real re-confirm safely re-links without growing the tuple).- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.attachment_id (
str) – SHA-256 of the attachment bytes to update.invoice_id (
str) – StableInvoiceidentifier to record as evidenced by this attachment.
- Return type:
- Returns:
The re-persisted
Attachmentmanifest carryinginvoice_idinAttachment.linked_invoice_ids.
- list_attachments(store, *, linked_to=None, kind=None)[source]¶
List attachment manifests, optionally filtered by link or kind.
- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.linked_to (
str|None) – When provided, return only attachments whoselinked_transaction_idsorlinked_invoice_idstuple contains this id.kind (
AttachmentKind|None) – When provided, return only attachments of thisAttachmentKind.
- Return type:
- Returns:
Filtered tuple of
Attachmentmanifests in store iteration order.