diff --git a/sdk/src/apl/file_apl.rs b/sdk/src/apl/file_apl.rs index e9b1be1..bac9cdf 100644 --- a/sdk/src/apl/file_apl.rs +++ b/sdk/src/apl/file_apl.rs @@ -24,7 +24,11 @@ impl APL for FileApl { async fn set(&self, auth_data: crate::AuthData) -> Result<()> { let path = std::path::Path::new(&self.path); debug!("reading from {:?}", &path); - let mut auths: FileStructure = serde_json::from_str(&std::fs::read_to_string(path)?)?; + let mut auths: FileStructure; + match path.is_file() { + true => auths = serde_json::from_str(&std::fs::read_to_string(path)?)?, + false => auths = FileStructure { 0: HashMap::new() }, + } auths.insert(auth_data.saleor_api_url.clone(), auth_data); diff --git a/sdk/src/webhooks/mod.rs b/sdk/src/webhooks/mod.rs index 0385de4..6f35039 100644 --- a/sdk/src/webhooks/mod.rs +++ b/sdk/src/webhooks/mod.rs @@ -3,11 +3,11 @@ pub mod sync_response; pub mod utils; use serde::{Deserialize, Serialize}; -use strum_macros::EnumString; +use strum_macros::{AsRefStr, EnumString}; use crate::config::Config; -#[derive(Debug, Clone, Serialize, Deserialize, EnumString)] +#[derive(Debug, Clone, Serialize, Deserialize, EnumString, AsRefStr)] //kinda annoying that in an apps manifest, the `AsyncWebhookEventType` is in SCREAMING_SNAKE_CASE, //but when receiving saleors webhook the header `saleor-event` is in snake_case, //have to serialize and deserialize the enum two different ways @@ -156,7 +156,7 @@ pub enum AsyncWebhookEventType { ShopMetadataUpdated, } -#[derive(Debug, Clone, Serialize, Deserialize, EnumString)] +#[derive(Debug, Clone, Serialize, Deserialize, EnumString, AsRefStr)] //kinda annoying that in an apps manifest, the `AsyncWebhookEventType` is in SCREAMING_SNAKE_CASE, //but when receiving saleors webhook the header `saleor-event` is in snake_case, //have to serialize and deserialize the enum two different ways diff --git a/sdk/src/webhooks/utils.rs b/sdk/src/webhooks/utils.rs index cde3dd1..3f0d1af 100644 --- a/sdk/src/webhooks/utils.rs +++ b/sdk/src/webhooks/utils.rs @@ -1,10 +1,11 @@ use http::HeaderMap; +use strum_macros::{AsRefStr, EnumString}; use crate::headers::SALEOR_EVENT_HEADER; use super::{AsyncWebhookEventType, SyncWebhookEventType}; -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum EitherWebhookType { Sync(SyncWebhookEventType), Async(AsyncWebhookEventType),