fix separate wasm and unix deps
Some checks failed
clippy / clippy (push) Has been cancelled

This commit is contained in:
djkato 2024-10-04 19:47:10 +02:00
parent b21d49a125
commit 3d916f1ff4
3 changed files with 61 additions and 28 deletions

View file

@ -40,11 +40,23 @@ dotenvy = { workspace = true }
envy = { workspace = true } envy = { workspace = true }
cynic = { workspace = true, features = ["http-surf"], optional = true } cynic = { workspace = true, features = ["http-surf"], optional = true }
surf = { workspace = true, optional = true } surf = { workspace = true, optional = true }
saleor-app-sdk = { workspace = true, optional = true }
[target.'cfg(target_family = "unix")'.dependencies]
saleor-app-sdk = { workspace = true, optional = true, features = [
"file_apl",
"redis_apl",
"tracing",
"middleware",
"webhook_utils",
] }
[target.'cfg(target_family = "wasm")'.dependencies]
saleor-app-sdk = { workspace = true, optional = true, features = ["bridge"] }
[build-dependencies] [build-dependencies]
cynic-codegen = { workspace = true, optional = true } cynic-codegen = { workspace = true, optional = true }
[features] [features]
ssr = [ ssr = [
"dep:axum", "dep:axum",
@ -106,7 +118,7 @@ tailwind-input-file = "style/base.css"
assets-dir = "public" assets-dir = "public"
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup. # The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "127.0.0.1:3000" site-addr = "0.0.0.0:3000"
# The port to use for automatic reload monitoring # The port to use for automatic reload monitoring
reload-port = 3001 reload-port = 3001

View file

@ -4,7 +4,6 @@ use crate::routes::home::Home;
use leptos::*; use leptos::*;
use leptos_meta::*; use leptos_meta::*;
use leptos_router::*; use leptos_router::*;
use saleor_app_sdk::bridge::AppBridge;
#[derive(Params, PartialEq)] #[derive(Params, PartialEq)]
pub struct UrlAppParams { pub struct UrlAppParams {
@ -15,7 +14,6 @@ pub struct UrlAppParams {
pub fn App() -> impl IntoView { pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc. // Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context(); provide_meta_context();
let app_bridge = AppBridge::new(Some(true)).unwrap();
view! { view! {
<Stylesheet id="leptos" href="/pkg/saleor-app-template-ui.css" /> <Stylesheet id="leptos" href="/pkg/saleor-app-template-ui.css" />

View file

@ -13,21 +13,21 @@ mod queries;
mod app; mod app;
mod components; mod components;
mod routes;
mod error_template; mod error_template;
mod routes;
#[tokio::main] #[tokio::main]
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
async fn main() -> Result<(), std::io::Error> { async fn main() -> Result<(), std::io::Error> {
use std::sync::Arc;
use axum::{middleware, routing::{get, post}, Router};
use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes };
use app::*; use app::*;
use axum::{
middleware,
routing::{get, post},
Router,
};
use fileserv::file_and_error_handler; use fileserv::file_and_error_handler;
use saleor_app_sdk::{manifest::{extension::AppExtensionBuilder, AppExtensionMount, AppExtensionTarget}, middleware::verify_webhook_signature::webhook_signature_verifier}; use leptos::*;
use tokio::sync::Mutex; use leptos_axum::{generate_route_list, LeptosRoutes};
use saleor_app_sdk::{ use saleor_app_sdk::{
cargo_info, cargo_info,
config::Config, config::Config,
@ -35,6 +35,12 @@ async fn main() -> Result<(), std::io::Error> {
webhooks::{AsyncWebhookEventType, WebhookManifestBuilder}, webhooks::{AsyncWebhookEventType, WebhookManifestBuilder},
SaleorApp, SaleorApp,
}; };
use saleor_app_sdk::{
manifest::{extension::AppExtensionBuilder, AppExtensionMount, AppExtensionTarget},
middleware::verify_webhook_signature::webhook_signature_verifier,
};
use std::sync::Arc;
use tokio::sync::Mutex;
use crate::routes::api::{manifest::manifest, register::register, webhooks::webhooks}; use crate::routes::api::{manifest::manifest, register::register, webhooks::webhooks};
@ -54,14 +60,18 @@ async fn main() -> Result<(), std::io::Error> {
AppExtensionBuilder::new() AppExtensionBuilder::new()
.set_url("/extensions/order_to_pdf") .set_url("/extensions/order_to_pdf")
.set_label("Order to PDF") .set_label("Order to PDF")
.add_permissions(vec![AppPermission::ManageOrders, AppPermission::ManageProducts, AppPermission::ManageProductTypesAndAttributes]) .add_permissions(vec![
AppPermission::ManageOrders,
AppPermission::ManageProducts,
AppPermission::ManageProductTypesAndAttributes,
])
.set_mount(AppExtensionMount::OrderDetailsMoreActions) .set_mount(AppExtensionMount::OrderDetailsMoreActions)
.set_target(AppExtensionTarget::Popup) .set_target(AppExtensionTarget::Popup)
.build() .build(),
) )
.build(); .build();
let app_state = AppState{ let app_state = AppState {
manifest: app_manifest, manifest: app_manifest,
config: config.clone(), config: config.clone(),
saleor_app: Arc::new(Mutex::new(saleor_app)), saleor_app: Arc::new(Mutex::new(saleor_app)),
@ -69,12 +79,22 @@ async fn main() -> Result<(), std::io::Error> {
}; };
let state_1 = app_state.clone(); let state_1 = app_state.clone();
let app = let app = Router::new()
Router::new() .leptos_routes_with_context(
.leptos_routes_with_context(&app_state, routes,move || provide_context(state_1.clone()) , App) &app_state,
routes,
move || provide_context(state_1.clone()),
App,
)
.fallback(file_and_error_handler) .fallback(file_and_error_handler)
.route("/api/webhooks", post(webhooks).route_layer(middleware::from_fn(webhook_signature_verifier))) .route(
.route("/api/register", post(register).route_layer(middleware::from_fn(webhook_signature_verifier))) "/api/webhooks",
post(webhooks).route_layer(middleware::from_fn(webhook_signature_verifier)),
)
.route(
"/api/register",
post(register).route_layer(middleware::from_fn(webhook_signature_verifier)),
)
.route("/api/manifest", get(manifest)) .route("/api/manifest", get(manifest))
.with_state(app_state.clone()); .with_state(app_state.clone());
@ -90,19 +110,19 @@ async fn main() -> Result<(), std::io::Error> {
.await?; .await?;
tracing::debug!("listening on {}", listener.local_addr()?); tracing::debug!("listening on {}", listener.local_addr()?);
let _= axum::serve(listener, app.into_make_service()) let _ = axum::serve(listener, app.into_make_service()).await;
.await;
Ok(()) Ok(())
} }
#[cfg(not(feature = "ssr"))] #[cfg(not(feature = "ssr"))]
pub fn main() { pub fn main() {
use saleor_app_sdk::bridge::AppBridge;
let app_bridge = AppBridge::new(Some(true)).unwrap();
// no client-side main function // no client-side main function
// unless we want this to work with e.g., Trunk for a purely client-side app // unless we want this to work with e.g., Trunk for a purely client-side app
// see lib.rs for hydration function instead // see lib.rs for hydration function instead
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
use saleor_app_sdk::config::Config; use saleor_app_sdk::config::Config;
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
@ -112,8 +132,13 @@ pub fn trace_to_std(config: &Config) -> Result<(), envy::Error> {
let filter = EnvFilter::builder() let filter = EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into()) .with_default_directive(LevelFilter::DEBUG.into())
.from_env().unwrap() .from_env()
.add_directive(format!("{}={}", env!("CARGO_PKG_NAME"), config.log_level).parse().unwrap()); .unwrap()
.add_directive(
format!("{}={}", env!("CARGO_PKG_NAME"), config.log_level)
.parse()
.unwrap(),
);
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_max_level(config.log_level) .with_max_level(config.log_level)
.with_env_filter(filter) .with_env_filter(filter)
@ -122,5 +147,3 @@ pub fn trace_to_std(config: &Config) -> Result<(), envy::Error> {
.init(); .init();
Ok(()) Ok(())
} }