From 4a9ef170fec063d47802a02f0a18b38cc7d24473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Djk=C3=A1=C5=A5o?= Date: Wed, 28 Feb 2024 00:31:25 +0100 Subject: [PATCH] readmes, move config to sdk --- Cargo.lock | 2 ++ README.md | 14 +++++------ saleor-app-sdk/Cargo.toml | 2 ++ saleor-app-sdk/README.md | 17 +++++++++++++ saleor-app-sdk/src/config.rs | 49 ++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 saleor-app-sdk/README.md create mode 100644 saleor-app-sdk/src/config.rs diff --git a/Cargo.lock b/Cargo.lock index b3888bf..ff9a691 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -959,6 +959,8 @@ name = "saleor-app-sdk" version = "0.1.0" dependencies = [ "anyhow", + "dotenvy", + "envy", "redis", "serde", "serde_json", diff --git a/README.md b/README.md index 2e18d31..2102275 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ This repo contains the following main components: -| Crate | Description | -| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | -| [**saleor-app-sdk**](https://crates.io/crates/saleor-app-sdk) | Types and utilities for making Saleor Apps | -| [**saleor-app-template**](https://github.com/djkato/saleor-app-template-rs/tree/master/saleor-app-template) | Simple template for making Saleor apps using axum | -| [**saleor-app-sitemap**](https://crates.io/crates/saleor-app-sitemap) | Saleor App for keeping sitemap.xml uptodate | +| Crate | Description | +| --------------------------------------------------------------------------------------------------- | ------------------------------------------------- | +| [**saleor-app-sdk**](https://crates.io/crates/saleor-app-sdk) | Types and utilities for making Saleor Apps | +| [**saleor-app-template**](https://github.com/djkato/saleor-apps-rs/tree/master/saleor-app-template) | Simple template for making Saleor apps using axum | +| [**saleor-app-sitemap**](https://crates.io/crates/saleor-app-sitemap) | Saleor App for keeping sitemap.xml uptodate | # Using this repo @@ -27,7 +27,7 @@ If using the `saleor-app-template`, create a new workspace member `cargo new `. +Workspace dependencies need to be managed manually. If you wanna add a new dependency to a single member do `cargo add --package `. If you want to use a shared dependency, add it to the root level `Cargo.toml`, then inside your member `Cargo.toml`add it under depencency like: ` = { workspace = true, features = [ "..." ] }`. @@ -38,4 +38,4 @@ Each workspace member has it's licensed in it's own directory. ### TL;DR: - saleor-app-sdk, saleor-app-template and the root structure fall under either MIT or Apache 2.0 at your convenience. -- Any other workspace members fall under `FSL-1.1-MIT.md`. If you want to use my apps in commercial environment, each app costs 10€ (or voluntarily more). Upon payment/donation you can automatically use the given app as if it had MIT-1 or Apache 2.0. +- Any other workspace members fall under FSL-1.1-MIT. If you want to use my apps in commercial environment, each app costs 10€ (or voluntarily more). Upon payment/donation you can automatically use the given app as if it had MIT-1 or Apache 2.0. diff --git a/saleor-app-sdk/Cargo.toml b/saleor-app-sdk/Cargo.toml index d78e847..60ada79 100644 --- a/saleor-app-sdk/Cargo.toml +++ b/saleor-app-sdk/Cargo.toml @@ -18,3 +18,5 @@ serde.workspace = true tracing.workspace = true tracing-subscriber.workspace = true serde_json.workspace = true +envy.workspace = true +dotenvy.workspace = true diff --git a/saleor-app-sdk/README.md b/saleor-app-sdk/README.md new file mode 100644 index 0000000..8a212d2 --- /dev/null +++ b/saleor-app-sdk/README.md @@ -0,0 +1,17 @@ +# Unofficial Saleor App SDK + +SDK for building [Saleor Apps](https://github.com/saleor/apps), inspired by The [Official Saleor SDK](https://github.com/saleor/apps) +This repo is very likely to introduce breaking changes as it's very early in development. Made specifically for the [Saleor App Template for Rust](https://github.com/djkato/saleor-apps-rs) + +Current Coverage: ~10% +[x] Base Types (Manifest, Webhooks, SaleorApp etc.) +[x] APLs (Only redis currently implemented) +[ ] JWT Management +[ ] Webhook utilities +[ ] Settings Manager +[ ] App Bridge +[ ] Handlers + +## Usage + +Check the git repo for example use in saleor-app-template diff --git a/saleor-app-sdk/src/config.rs b/saleor-app-sdk/src/config.rs new file mode 100644 index 0000000..d61fa10 --- /dev/null +++ b/saleor-app-sdk/src/config.rs @@ -0,0 +1,49 @@ +use serde::Deserialize; + +use tracing::{debug, Level}; + +use crate::apl::AplType; + +#[derive(Debug, Deserialize)] +#[serde(remote = "Level")] +pub enum LocalTracingLevel { + TRACE, + DEBUG, + INFO, + WARN, + ERROR, +} + +fn version_default() -> String { + ">=3.11.7<4".to_owned() +} + +#[derive(Deserialize, Debug, Clone)] +//#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub struct Config { + #[serde(default = "version_default")] + pub required_saleor_version: String, + pub saleor_app_id: String, + pub app_api_base_url: String, + pub apl: AplType, + pub apl_url: String, + #[serde(with = "LocalTracingLevel")] + pub log_level: tracing::Level, +} + +impl std::fmt::Display for Config { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl Config { + pub fn load() -> Result { + dotenvy::dotenv().unwrap(); + let env = envy::from_env::(); + if let Ok(e) = &env { + debug!("{}", e); + } + env + } +}