add features to feature gate big deps
This commit is contained in:
parent
7ce567db1c
commit
c9b233e78f
6 changed files with 70 additions and 28 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -2677,7 +2677,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
|||
|
||||
[[package]]
|
||||
name = "saleor-app-sdk"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
@ -2694,7 +2694,6 @@ dependencies = [
|
|||
"serde_json",
|
||||
"strum 0.26.2",
|
||||
"strum_macros 0.26.2",
|
||||
"tower",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "saleor-app-sdk"
|
||||
authors = ["Djkáťo <djkatovfx@gmail.com>"]
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
description = "Unofficial Saleor App SDK like library, made to for Rust."
|
||||
keywords = ["saleor", "sdk", "plugin"]
|
||||
|
@ -12,26 +12,47 @@ documentation = "https://github.com/djkato/saleor-apps-rs"
|
|||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[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 = [
|
||||
"aio",
|
||||
"tokio-comp",
|
||||
"connection-manager",
|
||||
] }
|
||||
serde.workspace = true
|
||||
axum.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
serde_json.workspace = true
|
||||
envy.workspace = true
|
||||
dotenvy.workspace = true
|
||||
tower = { workspace = true }
|
||||
rust_decimal = { workspace = true, features = ["serde-float"] }
|
||||
iso_currency = { workspace = true, features = ["with-serde", "iterator"] }
|
||||
reqwest = { version = "0.12.3", features = ["json"] }
|
||||
jsonwebtoken = "9.3.0"
|
||||
async-trait = "0.1.80"
|
||||
http = "1.1.0"
|
||||
url = "2.5.0"
|
||||
strum = "0.26.2"
|
||||
strum_macros = "0.26.2"
|
||||
], optional = true }
|
||||
|
||||
## Tracing
|
||||
tracing = { workspace = true, optional = true }
|
||||
tracing-subscriber = { workspace = true, optional = true }
|
||||
|
||||
## Needed for webhooks
|
||||
|
||||
[features]
|
||||
default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
|
||||
middleware = [
|
||||
"dep:axum",
|
||||
"dep:jsonwebtoken",
|
||||
"dep:url",
|
||||
"dep:reqwest",
|
||||
"dep:http",
|
||||
]
|
||||
redis_apl = ["dep:redis"]
|
||||
webhook_utils = ["dep:http"]
|
||||
tracing = ["dep:tracing", "dep:tracing-subscriber"]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod env_apl;
|
||||
pub mod file_apl;
|
||||
#[cfg(feature = "redis_apl")]
|
||||
pub mod redis_apl;
|
||||
|
||||
use crate::AuthData;
|
||||
|
@ -7,7 +8,6 @@ use anyhow::Result;
|
|||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum AplType {
|
||||
Redis,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::{debug, Level};
|
||||
|
||||
use crate::apl::AplType;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(remote = "Level")]
|
||||
pub enum LocalTracingLevel {
|
||||
|
@ -27,6 +29,7 @@ pub struct Config {
|
|||
pub app_iframe_base_url: String,
|
||||
pub apl: AplType,
|
||||
pub apl_url: String,
|
||||
#[cfg(feature = "tracing")]
|
||||
#[serde(with = "LocalTracingLevel")]
|
||||
pub log_level: tracing::Level,
|
||||
}
|
||||
|
@ -41,6 +44,7 @@ impl Config {
|
|||
pub fn load() -> Result<Self, envy::Error> {
|
||||
_ = dotenvy::dotenv();
|
||||
let env = envy::from_env::<Config>();
|
||||
#[cfg(feature = "tracing")]
|
||||
debug!("{:?}", &env);
|
||||
env
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ pub mod config;
|
|||
pub mod headers;
|
||||
pub mod locales;
|
||||
pub mod manifest;
|
||||
#[cfg(feature = "middleware")]
|
||||
pub mod middleware;
|
||||
pub mod webhooks;
|
||||
|
||||
|
@ -10,7 +11,9 @@ use apl::{AplType, APL};
|
|||
use config::Config;
|
||||
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)]
|
||||
pub struct AuthToken {
|
||||
|
@ -51,11 +54,25 @@ impl SaleorApp {
|
|||
use AplType::{Env, File, Redis};
|
||||
Ok(SaleorApp {
|
||||
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 {}),
|
||||
File => Box::new(FileApl {
|
||||
File => {
|
||||
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(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pub mod sync_response;
|
||||
#[cfg(feature = "webhook_utils")]
|
||||
pub mod utils;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
Loading…
Reference in a new issue