add features to feature gate big deps

This commit is contained in:
Djkáťo 2024-05-23 00:21:13 +02:00
parent 7ce567db1c
commit c9b233e78f
6 changed files with 70 additions and 28 deletions

3
Cargo.lock generated
View file

@ -2677,7 +2677,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]] [[package]]
name = "saleor-app-sdk" name = "saleor-app-sdk"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -2694,7 +2694,6 @@ dependencies = [
"serde_json", "serde_json",
"strum 0.26.2", "strum 0.26.2",
"strum_macros 0.26.2", "strum_macros 0.26.2",
"tower",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"url", "url",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "saleor-app-sdk" name = "saleor-app-sdk"
authors = ["Djkáťo <djkatovfx@gmail.com>"] authors = ["Djkáťo <djkatovfx@gmail.com>"]
version = "0.2.1" version = "0.2.2"
edition = "2021" edition = "2021"
description = "Unofficial Saleor App SDK like library, made to for Rust." description = "Unofficial Saleor App SDK like library, made to for Rust."
keywords = ["saleor", "sdk", "plugin"] keywords = ["saleor", "sdk", "plugin"]
@ -12,26 +12,47 @@ documentation = "https://github.com/djkato/saleor-apps-rs"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
anyhow.workspace = true anyhow = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
envy = { workspace = true }
dotenvy = { workspace = true }
rust_decimal = { workspace = true, features = ["serde-float"] }
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
strum = { version = "0.26.2" }
strum_macros = { version = "0.26.2" }
async-trait = { version = "0.1.80" }
## Needed for middleware
axum = { workspace = true, optional = true }
jsonwebtoken = { version = "9.3.0", optional = true }
url = { version = "2.5.0", optional = true }
reqwest = { version = "0.12.3", features = ["json"], optional = true }
http = { version = "1.1.0", optional = true }
# tower = { workspace = true, optional = true }
## Needed for APLs
redis = { workspace = true, features = [ redis = { workspace = true, features = [
"aio", "aio",
"tokio-comp", "tokio-comp",
"connection-manager", "connection-manager",
] } ], optional = true }
serde.workspace = true
axum.workspace = true ## Tracing
tracing.workspace = true tracing = { workspace = true, optional = true }
tracing-subscriber.workspace = true tracing-subscriber = { workspace = true, optional = true }
serde_json.workspace = true
envy.workspace = true ## Needed for webhooks
dotenvy.workspace = true
tower = { workspace = true } [features]
rust_decimal = { workspace = true, features = ["serde-float"] } default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
iso_currency = { workspace = true, features = ["with-serde", "iterator"] } middleware = [
reqwest = { version = "0.12.3", features = ["json"] } "dep:axum",
jsonwebtoken = "9.3.0" "dep:jsonwebtoken",
async-trait = "0.1.80" "dep:url",
http = "1.1.0" "dep:reqwest",
url = "2.5.0" "dep:http",
strum = "0.26.2" ]
strum_macros = "0.26.2" redis_apl = ["dep:redis"]
webhook_utils = ["dep:http"]
tracing = ["dep:tracing", "dep:tracing-subscriber"]

View file

@ -1,5 +1,6 @@
pub mod env_apl; pub mod env_apl;
pub mod file_apl; pub mod file_apl;
#[cfg(feature = "redis_apl")]
pub mod redis_apl; pub mod redis_apl;
use crate::AuthData; use crate::AuthData;
@ -7,7 +8,6 @@ use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AplType { pub enum AplType {
Redis, Redis,

View file

@ -1,9 +1,11 @@
use serde::Deserialize; use serde::Deserialize;
#[cfg(feature = "tracing")]
use tracing::{debug, Level}; use tracing::{debug, Level};
use crate::apl::AplType; use crate::apl::AplType;
#[cfg(feature = "tracing")]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(remote = "Level")] #[serde(remote = "Level")]
pub enum LocalTracingLevel { pub enum LocalTracingLevel {
@ -27,6 +29,7 @@ pub struct Config {
pub app_iframe_base_url: String, pub app_iframe_base_url: String,
pub apl: AplType, pub apl: AplType,
pub apl_url: String, pub apl_url: String,
#[cfg(feature = "tracing")]
#[serde(with = "LocalTracingLevel")] #[serde(with = "LocalTracingLevel")]
pub log_level: tracing::Level, pub log_level: tracing::Level,
} }
@ -41,6 +44,7 @@ impl Config {
pub fn load() -> Result<Self, envy::Error> { pub fn load() -> Result<Self, envy::Error> {
_ = dotenvy::dotenv(); _ = dotenvy::dotenv();
let env = envy::from_env::<Config>(); let env = envy::from_env::<Config>();
#[cfg(feature = "tracing")]
debug!("{:?}", &env); debug!("{:?}", &env);
env env
} }

View file

@ -3,6 +3,7 @@ pub mod config;
pub mod headers; pub mod headers;
pub mod locales; pub mod locales;
pub mod manifest; pub mod manifest;
#[cfg(feature = "middleware")]
pub mod middleware; pub mod middleware;
pub mod webhooks; pub mod webhooks;
@ -10,7 +11,9 @@ use apl::{AplType, APL};
use config::Config; use config::Config;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::apl::{env_apl::EnvApl, file_apl::FileApl, redis_apl::RedisApl}; use crate::apl::env_apl::EnvApl;
#[cfg(feature = "redis_apl")]
use crate::apl::{file_apl::FileApl, redis_apl::RedisApl};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthToken { pub struct AuthToken {
@ -51,11 +54,25 @@ impl SaleorApp {
use AplType::{Env, File, Redis}; use AplType::{Env, File, Redis};
Ok(SaleorApp { Ok(SaleorApp {
apl: match config.apl { apl: match config.apl {
Redis => Box::new(RedisApl::new(&config.apl_url, &config.app_api_base_url)?), Redis => {
if 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)?)
}
}
Env => Box::new(EnvApl {}), Env => Box::new(EnvApl {}),
File => Box::new(FileApl { File => {
path: "apl.txt".to_owned(), if 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(),
})
}
}
}, },
}) })
} }

View file

@ -1,4 +1,5 @@
pub mod sync_response; pub mod sync_response;
#[cfg(feature = "webhook_utils")]
pub mod utils; pub mod utils;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};