diff --git a/Cargo.lock b/Cargo.lock index 88c4368..efd6098 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2677,7 +2677,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "saleor-app-sdk" -version = "0.2.2" +version = "0.2.3" dependencies = [ "anyhow", "async-trait", diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0c540fc..090cbcb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,5 @@ [toolchain] -channel = "nightly-2024-03-23" +# channel = "nightly-2024-03-23" +## Toggle to this one for sdk releases +channel = "stable" targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index f5d5e08..2ff6b7b 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "saleor-app-sdk" authors = ["Djkáťo "] -version = "0.2.2" +version = "0.2.3" edition = "2021" description = "Unofficial Saleor App SDK like library, made to for Rust." keywords = ["saleor", "sdk", "plugin"] @@ -45,6 +45,7 @@ tracing-subscriber = { workspace = true, optional = true } ## Needed for webhooks [features] +# default = [] default = ["middleware", "redis_apl", "webhook_utils", "tracing"] middleware = [ "dep:axum", diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 92570c0..4bea2cc 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -12,8 +12,10 @@ use config::Config; use serde::{Deserialize, Serialize}; use crate::apl::env_apl::EnvApl; +#[cfg(feature = "file_apl")] +use crate::apl::file_apl::FileApl; #[cfg(feature = "redis_apl")] -use crate::apl::{file_apl::FileApl, redis_apl::RedisApl}; +use crate::apl::redis_apl::RedisApl; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AuthToken { @@ -52,28 +54,36 @@ pub struct SaleorApp { impl SaleorApp { pub fn new(config: &Config) -> anyhow::Result { use AplType::{Env, File, Redis}; - Ok(SaleorApp { - apl: match config.apl { + fn decide_apl(config: &Config) -> anyhow::Result> { + match config.apl { Redis => { - if cfg!(not(feature = "redis_apl")) { + #[cfg(feature = "redis_apl")] + return Ok(Box::new(RedisApl::new( + &config.apl_url, + &config.app_api_base_url, + )?)); + + #[cfg(not(feature = "redis_apl"))] + { dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl"); - Box::new(EnvApl {}) - } else { - Box::new(RedisApl::new(&config.apl_url, &config.app_api_base_url)?) + Ok(Box::new(EnvApl {})) } } - Env => Box::new(EnvApl {}), + Env => Ok(Box::new(EnvApl {})), File => { - if cfg!(not(feature = "file_apl")) { + #[cfg(feature = "file_apl")] + return Ok(Box::new(FileApl { + path: "apl.txt".to_owned(), + })); + #[cfg(not(feature = "file_apl"))] + { dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl"); - Box::new(EnvApl {}) - } else { - Box::new(FileApl { - path: "apl.txt".to_owned(), - }) + Ok(Box::new(EnvApl {})) } } - }, - }) + } + } + let apl = decide_apl(config)?; + Ok(SaleorApp { apl }) } }