saleor-apps-rs/sdk/src/lib.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

2024-02-27 16:50:48 +00:00
pub mod apl;
2024-03-06 15:42:04 +00:00
pub mod config;
2024-02-27 16:50:48 +00:00
pub mod headers;
2024-03-12 19:48:20 +00:00
pub mod locales;
2024-02-27 16:50:48 +00:00
pub mod manifest;
2024-03-06 15:42:04 +00:00
pub mod middleware;
2024-02-27 16:50:48 +00:00
pub mod webhooks;
2024-03-06 15:42:04 +00:00
use apl::{AplType, APL};
use config::Config;
2024-02-27 16:50:48 +00:00
use serde::{Deserialize, Serialize};
2024-03-06 15:42:04 +00:00
use crate::apl::{env_apl::EnvApl, file_apl::FileApl, redis_apl::RedisApl};
2024-02-27 16:50:48 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthToken {
pub auth_token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthData {
pub domain: Option<String>,
pub token: String,
pub saleor_api_url: String,
pub app_id: String,
pub jwks: Option<String>,
}
2024-03-12 19:48:20 +00:00
2024-02-27 16:50:48 +00:00
impl std::fmt::Display for AuthData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"(domain:{}\ntoken:{}\nsaleor_api_url:{}\napp_id:{}\njwks:{})",
self.domain.clone().unwrap_or_default(),
self.token,
self.saleor_api_url,
self.app_id,
self.jwks.clone().unwrap_or_default()
)
}
}
2024-03-06 15:42:04 +00:00
#[derive(Debug)]
pub struct SaleorApp {
pub apl: Box<dyn APL>,
}
impl SaleorApp {
pub fn new(config: &Config) -> anyhow::Result<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)?),
Env => Box::new(EnvApl {}),
File => Box::new(FileApl {
path: "apl.txt".to_owned(),
}),
},
})
}
2024-02-27 16:50:48 +00:00
}