invoance 0.2.0

Official Rust SDK for the Invoance compliance API
Documentation
//! Documents models.

use serde::Deserialize;

use super::{JsonObject, OrganizationPublic};

/// Parameters for [`DocumentsResource::anchor`](crate::resources::documents::DocumentsResource::anchor).
#[derive(Debug, Clone, Default)]
pub struct AnchorDocumentParams {
    /// Wire key `document_hash` (validated as 64-char lowercase hex).
    pub document_hash: String,
    /// Wire key `document_ref`.
    pub document_ref: Option<String>,
    /// Wire key `event_type`.
    pub event_type: Option<String>,
    /// Wire key `original_bytes_b64`.
    pub original_bytes_b64: Option<String>,
    /// Wire key `metadata`.
    pub metadata: Option<JsonObject>,
    /// Per-call idempotency key.
    pub idempotency_key: Option<String>,
    /// Wire key `trace_id`.
    pub trace_id: Option<String>,
}

/// The source bytes for [`DocumentsResource::anchor_file`](crate::resources::documents::DocumentsResource::anchor_file).
#[derive(Debug, Clone)]
pub enum FileSource {
    /// A filesystem path; `document_ref` defaults to the basename.
    Path(std::path::PathBuf),
    /// Raw file bytes.
    Bytes(Vec<u8>),
}

/// Parameters for [`DocumentsResource::anchor_file`](crate::resources::documents::DocumentsResource::anchor_file).
#[derive(Debug, Clone)]
pub struct AnchorFileParams {
    /// File path on disk, or raw bytes of the file contents.
    pub file: FileSource,
    /// Human-readable reference. Defaults to filename when a path is given.
    pub document_ref: Option<String>,
    /// Classification string (e.g. "invoice", "contract").
    pub event_type: Option<String>,
    /// Arbitrary JSON metadata attached to the anchor.
    pub metadata: Option<JsonObject>,
    /// Idempotency key for safe retries.
    pub idempotency_key: Option<String>,
    /// Skip uploading the original file bytes. Default: false.
    pub skip_original: bool,
    /// Optional trace ID to associate this document with a trace.
    pub trace_id: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct AnchorDocumentResponse {
    pub event_id: String,
    pub created_at: String,
    pub document_hash: String,
    pub status: String,
}

/// Parameters for [`DocumentsResource::list`](crate::resources::documents::DocumentsResource::list).
#[derive(Debug, Clone, Default)]
pub struct ListDocumentsParams {
    pub page: Option<u32>,
    pub limit: Option<u32>,
    pub date_from: Option<String>,
    pub date_to: Option<String>,
    pub document_ref: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct DocumentListItem {
    pub event_id: String,
    pub document_ref: String,
    pub document_hash: String,
    pub event_type: String,
    pub has_original: bool,
    pub created_at: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct ListDocumentsResponse {
    pub documents: Vec<DocumentListItem>,
    pub page: u32,
    pub limit: u32,
    pub total: u64,
    pub has_more: bool,
}

#[derive(Debug, Clone, Deserialize)]
pub struct DocumentEvent {
    pub event_id: String,
    pub tenant_id: String,
    pub document_ref: String,
    pub document_hash: String,
    pub signature_b64: String,
    pub signed_payload_b64: String,
    pub public_key_b64: String,
    pub has_original: bool,
    #[serde(default)]
    pub metadata: Option<JsonObject>,
    pub created_at: String,
    #[serde(default)]
    pub organization: Option<OrganizationPublic>,
}

/// Parameters for [`DocumentsResource::verify`](crate::resources::documents::DocumentsResource::verify).
#[derive(Debug, Clone, Default)]
pub struct VerifyDocumentParams {
    pub document_hash: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct VerifyDocumentResponse {
    pub event_id: String,
    pub match_result: bool,
    pub document_ref: String,
    pub anchored_hash: String,
    pub submitted_hash: String,
    pub anchored_at: String,
    #[serde(default)]
    pub organization: Option<OrganizationPublic>,
}