Skip to content

Commit

Permalink
Templater as a separate plugin.
Browse files Browse the repository at this point in the history
Removed a huge amount of code.
  • Loading branch information
GamePad64 committed Oct 4, 2024
1 parent 092ccb3 commit 31c0a07
Show file tree
Hide file tree
Showing 27 changed files with 225 additions and 339 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ notifico-telegram = { path = "notifico-telegram" }
notifico-smtp = { path = "notifico-smtp" }
notifico-subscription = { path = "notifico-subscription" }
notifico-whatsapp = { path = "notifico-whatsapp" }
notifico-templater = { path = "notifico-templater" }
serde_yaml = "0.9.23"
actix = "0.13.5"
axum = "0.7.6"
Expand All @@ -38,7 +39,8 @@ lto = true
codegen-units = 1

[workspace]
members = [".", "notifico-core", "notifico-smtp", "notifico-telegram", "notifico-subscription/migration", "notifico-subscription", "notifico-whatsapp"]
members = [".", "notifico-core", "notifico-smtp", "notifico-telegram", "notifico-subscription/migration", "notifico-subscription", "notifico-whatsapp", "notifico-templater"]

[workspace.dependencies]
sea-orm = { version = "1.1.0-rc.1", features = ["sqlx-sqlite", "sqlx-postgres", "runtime-tokio-rustls", "macros"] }
reqwest = "0.12.8"
7 changes: 2 additions & 5 deletions notifico-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ edition = "2021"
async-trait = "0.1.82"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
uuid = { version = "1.10.0", features = ["v4", "serde"] }
reqwest = "0.12.7"
url = "2.5.2"
uuid = { version = "1.10.0", features = ["serde"] }
tracing = "0.1.40"
tokio = "1.40.0"
reqwest-middleware = { version = "0.3.3", features = ["json"] }
reqwest-tracing = "0.5.3"

7 changes: 5 additions & 2 deletions notifico-core/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::EngineError;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
Expand Down Expand Up @@ -26,16 +27,17 @@ pub trait TypedCredential: for<'de> Deserialize<'de> {
const CREDENTIAL_TYPE: &'static str;
}

#[async_trait]
pub trait Credentials: Send + Sync {
fn get_credential(
async fn get_credential(
&self,
project: Uuid,
r#type: &str,
name: &str,
) -> Result<Credential, EngineError>;
}

pub fn get_typed_credential<T>(
pub async fn get_typed_credential<T>(
credentials: &dyn Credentials,
project: Uuid,
name: &str,
Expand All @@ -45,5 +47,6 @@ where
{
credentials
.get_credential(project, T::CREDENTIAL_TYPE, name)
.await
.and_then(|c| c.into_typed())
}
5 changes: 3 additions & 2 deletions notifico-core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::engine::plugin::{EnginePlugin, StepOutput};
use crate::error::EngineError;
use crate::pipeline::SerializedStep;
use crate::recipient::Recipient;
use crate::templater::RenderResponse;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::borrow::Cow;
Expand All @@ -17,14 +18,14 @@ pub mod plugin;
#[serde(transparent)]
pub struct EventContext(pub Map<String, Value>);

#[derive(Default, Debug)]
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct PipelineContext {
pub project_id: Uuid,
pub recipient: Option<Recipient>,
pub trigger_event: String,
pub event_context: EventContext,
pub plugin_contexts: Map<String, Value>,
pub messages: Vec<Map<String, Value>>,
pub messages: Vec<RenderResponse>,
pub channel: String,
}

Expand Down
2 changes: 1 addition & 1 deletion notifico-core/src/engine/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::any::Any;
use std::borrow::Cow;

pub enum StepOutput {
None,
Continue,
Interrupt,
}

Expand Down
8 changes: 0 additions & 8 deletions notifico-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::templater::TemplaterError;
use std::borrow::Cow;
use std::error::Error;
use uuid::Uuid;
Expand All @@ -7,7 +6,6 @@ use uuid::Uuid;
pub enum EngineError {
InvalidCredentialFormat,
CredentialNotFound(Cow<'static, str>, String),
TemplaterError(TemplaterError),
PluginNotFound(String),
ContactNotFound(String),
InvalidContactFormat,
Expand All @@ -18,9 +16,3 @@ pub enum EngineError {
InternalError(Box<dyn Error>),
InvalidStep(serde_json::Error),
}

impl From<TemplaterError> for EngineError {
fn from(err: TemplaterError) -> Self {
EngineError::TemplaterError(err)
}
}
2 changes: 1 addition & 1 deletion notifico-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl PipelineRunner {
for step in pipeline.steps.iter() {
let result = engine.execute_step(&mut context, step).await;
match result {
Ok(StepOutput::None) => continue,
Ok(StepOutput::Continue) => continue,
Ok(StepOutput::Interrupt) => break,
Err(err) => {
error!("Error executing step: {:?}", err);
Expand Down
6 changes: 6 additions & 0 deletions notifico-core/src/templater.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct RenderResponse(pub Map<String, Value>);
45 changes: 0 additions & 45 deletions notifico-core/src/templater/mod.rs

This file was deleted.

53 changes: 0 additions & 53 deletions notifico-core/src/templater/service.rs

This file was deleted.

17 changes: 1 addition & 16 deletions notifico-smtp/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
use lettre::message::Mailbox;
use serde::{Deserialize, Serialize};

pub const EMAIL_FROM: &str = "email.from";
pub const EMAIL_SUBJECT: &str = "email.subject";
pub const EMAIL_BODY_HTML: &str = "email.body_html";
pub const EMAIL_BODY_PLAINTEXT: &str = "email.body_plaintext";
// pub const EMAIL_LIST_UNSUBSCRIBE: &str = "email.list_unsubscribe";

#[derive(Serialize, Deserialize, Clone)]
pub struct Email {
#[serde(rename = "email.from")]
pub from: Mailbox,
#[serde(rename = "email.subject")]
pub subject: String,
#[serde(rename = "email.body_html")]
pub body_html: String,
#[serde(rename = "email.body_plaintext")]
pub body_plaintext: String,
pub struct PluginContext {
#[serde(rename = "email.list_unsubscribe")]
pub list_unsubscribe: Option<String>,
}
Loading

0 comments on commit 31c0a07

Please sign in to comment.