lightcone 0.7.1

Rust SDK for the Lightcone Protocol — unified native + WASM client
Documentation
//! Notification sub-client — fetch and dismiss notifications.

use crate::client::LightconeClient;
use crate::domain::notification::Notification;
use crate::error::SdkError;
use crate::http::RetryPolicy;
use serde::{Deserialize, Serialize};

pub struct Notifications<'a> {
    pub(crate) client: &'a LightconeClient,
}

#[derive(Deserialize)]
struct NotificationsResponse {
    notifications: Vec<Notification>,
}

#[derive(Serialize)]
struct DismissRequest {
    notification_id: String,
}

impl<'a> Notifications<'a> {
    pub async fn fetch(&self) -> Result<Vec<Notification>, SdkError> {
        let url = format!("{}/api/notifications", self.client.http.base_url());
        let body: NotificationsResponse =
            self.client.http.get(&url, RetryPolicy::Idempotent).await?;
        Ok(body.notifications)
    }

    /// Same as [`Self::fetch`], but forwards the supplied raw `Cookie` header (`privy-token` and/or `lightcone-token`) for this
    /// call instead of the SDK's process-wide token store. For server-side
    /// cookie forwarding (SSR / server functions).
    pub async fn fetch_with_cookies(
        &self,
        cookie_header: &str,
    ) -> Result<Vec<Notification>, SdkError> {
        let url = format!("{}/api/notifications", self.client.http.base_url());
        let body: NotificationsResponse = self
            .client
            .http
            .get_with_cookies(&url, RetryPolicy::Idempotent, cookie_header)
            .await?;
        Ok(body.notifications)
    }

    pub async fn dismiss(&self, notification_id: &str) -> Result<(), SdkError> {
        let url = format!("{}/api/notifications/dismiss", self.client.http.base_url());
        let body = DismissRequest {
            notification_id: notification_id.to_string(),
        };
        let _: serde_json::Value = self
            .client
            .http
            .post(&url, &body, RetryPolicy::None)
            .await?;
        Ok(())
    }
}