Skip to main content

systemprompt_identifiers/
notifications.rs

1//! Notification identifiers.
2//!
3//! Notifications, subscriptions and rules are UUID-backed.
4//! [`NotificationStreamId`] is a declared stream key from
5//! `services/notifications/*.yaml`, checked to 1-64 characters of
6//! lowercase ASCII letters, digits, `_` and `-`.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11use crate::error::IdValidationError;
12
13crate::define_id!(NotificationId, uuid);
14crate::define_id!(NotificationSubscriptionId, uuid);
15crate::define_id!(NotificationRuleId, uuid);
16crate::define_id!(NotificationStreamId, checked, validate_stream_id);
17
18const STREAM_ID_MAX_LEN: usize = 64;
19
20fn validate_stream_id(value: &str) -> Result<(), IdValidationError> {
21    if value.is_empty() {
22        return Err(IdValidationError::empty("NotificationStreamId"));
23    }
24    if value.len() > STREAM_ID_MAX_LEN {
25        return Err(IdValidationError::invalid(
26            "NotificationStreamId",
27            "must be at most 64 characters",
28        ));
29    }
30    if !value
31        .bytes()
32        .all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'_' || b == b'-')
33    {
34        return Err(IdValidationError::invalid(
35            "NotificationStreamId",
36            "must contain only lowercase letters, digits, '_' and '-'",
37        ));
38    }
39    Ok(())
40}