areev 0.2.0

Rust SDK for the Areev knowledge database — gRPC and HTTP transports
Documentation
//! `Namespaces` resource — namespace-level purge.
//!
//! Mirrors the Python SDK's `client.namespaces.*` surface.

use serde_json::Value;

use crate::error::Result;
use crate::http::HttpClient;
use crate::resources::grains::confirm_error;

/// Namespace operations.
///
/// Access via [`crate::Areev::namespaces`].
pub struct Namespaces<'a> {
    http: &'a HttpClient,
    memory_id: String,
}

impl<'a> Namespaces<'a> {
    /// Internal constructor — use [`crate::Areev::namespaces`].
    pub(crate) fn new(http: &'a HttpClient, memory_id: String) -> Self {
        Self { http, memory_id }
    }

    /// Purge every grain in `namespace`
    /// (`DELETE FROM grains WHERE ns_hash`).
    ///
    /// **IRREVERSIBLE.** There is no undo — all grains in the namespace
    /// are dropped. Emits an audit event. Requires: admin scope.
    ///
    /// Under a HIPAA-bound memory a forced namespace purge is
    /// hard-blocked by the policy engine (403, surfaced as
    /// [`crate::AreevError::HipaaPolicyViolation`] / [`crate::AreevError::Authorization`]);
    /// the SDK never gates this client-side — it issues the request and
    /// surfaces the server's verdict.
    ///
    /// **Not auto-retried.**
    ///
    /// # Errors
    ///
    /// Returns [`crate::AreevError::Validation`] (`SDK-E002`) when
    /// `confirm` is not `true`.
    pub async fn purge(&self, namespace: &str, confirm: bool) -> Result<Value> {
        if !confirm {
            return Err(confirm_error("namespaces.purge"));
        }
        let path = format!("/memories/{}/namespaces/{}", self.memory_id, namespace);
        self.http._delete_no_retry(&path).await
    }
}