mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: Tyler Longwell <tlongwell@block.xyz> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Mari <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Quinn <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Sami <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Perci <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
111 lines
3.6 KiB
Rust
111 lines
3.6 KiB
Rust
#![deny(unsafe_code)]
|
|
#![warn(missing_docs)]
|
|
//! `buzz-sdk` — typed Nostr event builders for Buzz operations.
|
|
//!
|
|
//! # Mental Model
|
|
//!
|
|
//! ```text
|
|
//! caller params → builder fn → validates → EventBuilder → caller signs → Event
|
|
//! ```
|
|
//!
|
|
//! Each builder function validates its inputs and returns an [`nostr::EventBuilder`].
|
|
//! The caller signs with their own keys: `builder.sign_with_keys(&keys)?`.
|
|
//! No keys are held here. No network calls are made.
|
|
|
|
pub mod builders;
|
|
pub mod mentions;
|
|
pub mod nip_oa;
|
|
|
|
pub use builders::*;
|
|
|
|
/// Re-export kind constants so consumers don't need buzz-core directly.
|
|
pub use buzz_core::kind;
|
|
|
|
/// Thread reference for reply builders (NIP-10 markers).
|
|
///
|
|
/// - Direct reply (root == parent): emits `["e", root, "", "reply"]`
|
|
/// - Nested reply (root ≠ parent): emits `["e", root, "", "root"]` + `["e", parent, "", "reply"]`
|
|
pub struct ThreadRef {
|
|
/// The root event of the thread.
|
|
pub root_event_id: nostr::EventId,
|
|
/// The immediate parent being replied to.
|
|
pub parent_event_id: nostr::EventId,
|
|
}
|
|
|
|
/// Metadata for diff/patch messages (kind 40008).
|
|
pub struct DiffMeta {
|
|
/// Repository URL — required, must start with `http://` or `https://`.
|
|
pub repo_url: String,
|
|
/// Commit SHA — required, minimum 7 hex characters.
|
|
pub commit_sha: String,
|
|
/// Optional file path within the repository.
|
|
pub file_path: Option<String>,
|
|
/// Optional parent commit SHA — minimum 7 hex chars if present.
|
|
pub parent_commit: Option<String>,
|
|
/// Optional branch pair `(source, target)` — both or neither.
|
|
pub branch: Option<(String, String)>,
|
|
/// Optional pull request number — must be positive.
|
|
pub pr_number: Option<u32>,
|
|
/// Optional programming language identifier.
|
|
pub language: Option<String>,
|
|
/// Optional human-readable description.
|
|
pub description: Option<String>,
|
|
/// Whether the diff was truncated due to size.
|
|
pub truncated: bool,
|
|
/// Optional alt text for accessibility.
|
|
pub alt_text: Option<String>,
|
|
}
|
|
|
|
/// Vote direction for `build_vote`.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum VoteDirection {
|
|
/// Upvote — content `"+"`.
|
|
Up,
|
|
/// Downvote — content `"-"`.
|
|
Down,
|
|
}
|
|
|
|
/// A NIP-30 custom emoji tag payload.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct CustomEmoji {
|
|
/// The shortcode without surrounding colons.
|
|
pub shortcode: String,
|
|
/// Image URL for this custom emoji.
|
|
pub url: String,
|
|
}
|
|
|
|
/// Channel type.
|
|
pub use buzz_core::channel::ChannelType as ChannelKind;
|
|
/// Channel visibility.
|
|
pub use buzz_core::channel::ChannelVisibility as Visibility;
|
|
/// Member role.
|
|
pub use buzz_core::channel::MemberRole;
|
|
|
|
/// Errors returned by SDK builder functions.
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum SdkError {
|
|
/// Content exceeds the maximum allowed size.
|
|
#[error("content exceeds maximum size of {max} bytes (got {got})")]
|
|
ContentTooLarge {
|
|
/// Maximum allowed bytes.
|
|
max: usize,
|
|
/// Actual byte count.
|
|
got: usize,
|
|
},
|
|
/// A tag could not be constructed.
|
|
#[error("invalid tag: {0}")]
|
|
InvalidTag(String),
|
|
/// Emoji string exceeds 64 characters.
|
|
#[error("emoji exceeds maximum length of 64 characters")]
|
|
EmojiTooLong,
|
|
/// More than 50 mentions were supplied.
|
|
#[error("too many mentions (max 50)")]
|
|
TooManyMentions,
|
|
/// Diff metadata failed validation.
|
|
#[error("invalid diff metadata: {0}")]
|
|
InvalidDiffMeta(String),
|
|
/// Input failed validation (e.g. malformed pubkey).
|
|
#[error("invalid input: {0}")]
|
|
InvalidInput(String),
|
|
}
|