1pub mod allowlist;
2pub mod decode;
3pub mod redact;
4pub mod render;
5pub mod schema;
6pub mod transport;
7
8use std::future::Future;
9
10use serde_json::{Map, Value};
11
12pub use allowlist::ensure_url_allowed;
13pub use decode::{DecodedBody, decode_response};
14pub use redact::Redactor;
15pub use render::TemplateRenderer;
16pub use schema::{AllowRule, CommandMode, ResultDecode, ResultExtract, ResultTemplate};
17pub use transport::ResolvedTransport;
18
19#[derive(Debug, Clone)]
21pub enum PreparedBody {
22 Empty,
23 Json(Value),
24 Form(Vec<(String, String)>),
25 Multipart(Vec<PreparedMultipartPart>),
26 RawBytes {
27 bytes: Vec<u8>,
28 content_type: Option<String>,
29 },
30}
31
32#[derive(Debug, Clone)]
34pub struct PreparedMultipartPart {
35 pub name: String,
36 pub bytes: Vec<u8>,
37 pub content_type: Option<String>,
38 pub filename: Option<String>,
39}
40
41#[derive(Debug, Clone)]
43pub struct ExecutionResult {
44 pub status: u16,
45 pub url: String,
46 pub result: Value,
47 pub decoded: Value,
48}
49
50#[derive(Debug, Clone)]
52pub struct RawExecutionResult {
53 pub status: u16,
54 pub url: String,
55 pub body: Vec<u8>,
56 pub content_type: Option<String>,
57}
58
59#[derive(Debug, Clone)]
62pub struct ExecutionContext {
63 pub key: String,
64 pub mode: CommandMode,
65 pub allow_rules: Vec<AllowRule>,
66 pub transport: ResolvedTransport,
67 pub result_template: ResultTemplate,
68 pub args: Map<String, Value>,
69 pub redactor: Redactor,
70}
71
72pub trait ProtocolExecutor {
78 type PreparedData: Clone + std::fmt::Debug + Send + Sync;
80
81 fn execute(
83 &mut self,
84 data: &Self::PreparedData,
85 context: &ExecutionContext,
86 ) -> impl Future<Output = anyhow::Result<RawExecutionResult>> + Send;
87}