delopay 0.7.0

Official Rust SDK for the DeloPay payments API
Documentation
//! The merchant audit-log models.
//!
//! What a merchant is allowed to see of their own log, which is deliberately
//! less than what the platform records. Two redactions are structural rather
//! than cosmetic, and both are documented on the types that carry them:
//! a DeloPay actor is never named, and a DeloPay session is never described.

use serde::Deserialize;
use serde_json::Value;

/// The parties a merchant can see in their own log.
///
/// `"delopay"` covers support acting on the account and the platform itself,
/// deliberately as one value: which of DeloPay's mechanisms it was is not the
/// merchant's question, and splitting it would leak internal structure.
///
/// Open-ended (`String`) rather than an enum, so a party added later reaches
/// the caller as data instead of a deserialization failure. Known values:
/// `"team_member"`, `"api_key"`, `"delopay"`, `"system"`.
pub type MerchantAuditActorKind = String;

/// Which relationship an impersonated change was made under.
///
/// `None` means **unknown** — a row written before this was recorded — which
/// is not the same as `"self_acted"`. Known values: `"self_acted"`,
/// `"admin_for_merchant"`, `"merchant_for_team_member"`.
pub type MerchantAuditImpersonationKind = String;

/// Who acted, as a merchant is allowed to see it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditActorInfo {
    /// `None` for a DeloPay actor: the merchant learns that support acted, not
    /// which employee it was.
    #[serde(default)]
    pub id: Option<String>,
    /// See [`MerchantAuditActorKind`].
    pub kind: MerchantAuditActorKind,
    /// The team member's email, or the label for a non-human actor.
    #[serde(default)]
    pub name: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The sign-in a change was made in.
///
/// Only ever present for the merchant's **own** people. A DeloPay support
/// session carries none: the employee's device, address and city are not the
/// merchant's to read back.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditSessionInfo {
    /// Session id — the grouping key for "everything done in one sign-in".
    pub id: String,
    /// Address the session signed in from.
    #[serde(default)]
    pub ip_address: Option<String>,
    #[serde(default)]
    pub user_agent: Option<String>,
    #[serde(default)]
    pub country_code: Option<String>,
    #[serde(default)]
    pub city: Option<String>,
    /// Approximate — derived from the IP, so a neighbourhood, not an address.
    #[serde(default)]
    pub latitude: Option<f64>,
    /// Approximate, on the same terms as [`latitude`](Self::latitude).
    #[serde(default)]
    pub longitude: Option<f64>,
    #[serde(default)]
    pub auth_method: Option<String>,
    #[serde(default)]
    pub started_at: Option<String>,
    #[serde(default)]
    pub last_seen_at: Option<String>,
    /// Set when the session was ended early.
    #[serde(default)]
    pub revoked_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One recorded change on a merchant's account or one of its shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogEntry {
    /// Unique entry id, as taken by [`crate::Audit::retrieve`].
    pub id: String,
    /// Who the change is attributed to.
    pub actor: MerchantAuditActorInfo,
    /// The person really acting, when it was one of the merchant's own — an
    /// admin signed in as a team member. `None` when nobody was impersonating,
    /// and also when it was DeloPay: `impersonation_kind` says an admin acted,
    /// and `actor` already says it was DeloPay.
    #[serde(default)]
    pub real_actor: Option<MerchantAuditActorInfo>,
    /// See [`MerchantAuditImpersonationKind`] — `None` is unknown, not
    /// "nobody impersonated".
    #[serde(default)]
    pub impersonation_kind: Option<MerchantAuditImpersonationKind>,
    /// The sign-in the change was made in, where the merchant may see it.
    #[serde(default)]
    pub session: Option<MerchantAuditSessionInfo>,
    /// The shop the change belongs to, when it was shop-scoped.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// What was done, e.g. `"update"`.
    pub action: String,
    /// What it was done to, e.g. `"business_profile"`.
    pub entity_type: String,
    #[serde(default)]
    pub entity_id: Option<String>,
    /// What the entity was called. `None` when it has since been deleted.
    #[serde(default)]
    pub entity_name: Option<String>,
    /// Which fields the change touched. Names only, never values — the raw
    /// payload can carry connector credentials, so it is never forwarded.
    #[serde(default)]
    pub changed_fields: Vec<String>,
    /// ISO 8601 timestamp of the change.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One page of a merchant's audit log.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogListResponse {
    /// The page, newest first.
    pub entries: Vec<MerchantAuditLogEntry>,
    /// How many entries the filter matched in total, which is what makes
    /// paging terminable without probing for the end.
    pub total_count: i64,
    /// Offset this page was read at.
    pub offset: i64,
    /// Page size this page was read with.
    pub limit: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}