use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::Duration;
#[derive(Debug, Clone, Copy)]
pub struct ServiceDefinition {
pub name: &'static str,
pub version: &'static str,
pub methods: &'static [&'static str],
}
#[derive(Debug, Clone)]
pub struct EdgeConfig {
pub api_key: String,
pub server_url: Option<String>,
pub edge_name: Option<String>,
pub labels: HashMap<String, String>,
pub version: Option<String>,
pub hostname: Option<String>,
pub ip_address: Option<String>,
pub heartbeat_interval: Duration,
pub timeout: Duration,
pub reconnect_wait: Duration,
pub max_reconnects: i32,
}
impl Default for EdgeConfig {
fn default() -> Self {
Self {
api_key: String::new(),
server_url: None,
edge_name: None,
labels: HashMap::new(),
version: None,
hostname: None,
ip_address: None,
heartbeat_interval: Duration::from_secs(30),
timeout: Duration::from_secs(30),
reconnect_wait: Duration::from_secs(2),
max_reconnects: -1,
}
}
}
#[derive(Debug, Clone)]
pub struct CenterConfig {
pub server_url: String,
pub api_key: Option<String>,
pub app_id: Option<String>,
pub timeout: Duration,
}
impl Default for CenterConfig {
fn default() -> Self {
Self {
server_url: String::new(),
api_key: None,
app_id: None,
timeout: Duration::from_secs(30),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConnectionQualityLevel {
Excellent,
Good,
Fair,
Poor,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConnectionState {
Connecting,
Connected,
Reconnecting,
Disconnected,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ConnectionQuality {
pub state: ConnectionState,
pub latency_ms: Option<f64>,
pub avg_latency_ms: Option<f64>,
pub messages_sent_per_second: f64,
pub messages_received_per_second: f64,
pub total_messages_sent: u64,
pub total_messages_received: u64,
pub last_ping_at: Option<u64>,
pub quality_level: ConnectionQualityLevel,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct EdgeInfo {
pub id: String,
pub name: String,
#[serde(default)]
pub app_id: String,
pub status: String,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub services: Vec<String>,
pub groups: Option<Vec<String>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct DiscoverOptions {
pub service_name: Option<String>,
pub labels: Option<HashMap<String, String>>,
pub online_only: Option<bool>,
}
#[derive(Debug, Clone)]
pub struct CallOptions {
pub timeout: Option<Duration>,
pub retries: Option<u32>,
pub retry_delay: Option<Duration>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum KeyType {
Edge,
Center,
Client,
Admin,
AppMaster,
SyncKey,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum KeyStatus {
Active,
Expired,
Revoked,
Disabled,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct KeyResources {
pub services: Option<Vec<String>>,
pub streams: Option<Vec<String>>,
pub kv_buckets: Option<Vec<String>>,
pub events: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct KeyMetadata {
pub id: String,
pub app_id: String,
pub name: String,
#[serde(rename = "type")]
pub key_type: KeyType,
pub edge_id: Option<String>,
#[serde(default)]
pub scopes: Vec<String>,
pub resources: Option<KeyResources>,
pub labels: Option<HashMap<String, String>>,
pub status: KeyStatus,
pub created_at: String,
pub expires_at: Option<String>,
pub last_used_at: Option<String>,
pub revoked_at: Option<String>,
pub revoke_reason: Option<String>,
pub groups: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct CreateKeyOptions {
pub name: String,
#[serde(rename = "type")]
pub key_type: KeyType,
pub edge_id: Option<String>,
pub scopes: Option<Vec<String>>,
pub scope_bundle: Option<String>,
pub expires_in: Option<String>,
pub labels: Option<HashMap<String, String>>,
pub groups: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct CreateKeyResult {
pub key: KeyMetadata,
pub api_key: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ListKeysOptions {
#[serde(rename = "type")]
pub key_type: Option<KeyType>,
pub labels: Option<HashMap<String, String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlatformResponse<T> {
pub success: bool,
#[serde(default)]
pub data: Option<T>,
#[serde(default)]
pub error: Option<ErrorPayload>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceResponse<T> {
pub success: bool,
#[serde(default)]
pub result: Option<T>,
#[serde(default)]
pub error: Option<ErrorPayload>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ErrorPayload {
pub code: String,
pub message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamRequest<T> {
pub reply_subject: String,
pub data: T,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StreamAck {
pub status: String,
pub cancel_subject: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct RegisterPayload {
pub name: String,
#[serde(rename = "type")]
pub edge_type: String,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub version: String,
#[serde(default)]
pub hostname: String,
#[serde(default)]
pub ip_address: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ServiceRegisterPayload {
pub name: String,
pub version: String,
pub location: String,
pub edge_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct ServiceDeregisterPayload {
pub service_id: String,
}
#[derive(Debug, Clone)]
pub struct ParsedEdgeKey {
pub app_id: String,
pub edge_id: String,
pub server_url: Option<String>,
pub http_url: Option<String>,
pub secret: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct WebhookMethodMeta {
pub method: String,
pub secret_mode: String,
pub description: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct WebhookRegistration {
pub id: String,
pub edge_id: String,
pub service: String,
pub method: String,
pub app_id: String,
#[serde(default)]
pub secret: String,
#[serde(default)]
pub secret_mode: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub call_count: i64,
pub last_used_at: Option<String>,
pub created_at: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct RequestMetadata {
#[serde(default)]
pub request_id: Option<String>,
#[serde(default)]
pub source_edge: Option<String>,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub timestamp: Option<u64>,
}
#[derive(Debug, Clone, Default)]
pub struct RequestContext {
pub metadata: RequestMetadata,
}