Compare commits
3 commits
8744fb6acf
...
3d916f1ff4
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3d916f1ff4 | ||
![]() |
b21d49a125 | ||
![]() |
59c1ec058c |
25 changed files with 110970 additions and 1057 deletions
|
@ -25,7 +25,7 @@ SITEMAP_ALLOWED_HOST="https://api.example.com"
|
|||
|
||||
## THESE VARIABLES ARE FOR SIMPLE-PAYMENT-GATEWAY APP
|
||||
#To see all possible options, check simple-payment-gateway/src/app:GatewayTypes
|
||||
ACTIVE_GATEWAYS="cod,cash,transfer"
|
||||
ACTIVE_PAYMENT_METHODS="cod,cash,transfer"
|
||||
# only Sk,En available :). Determines what language the gateway names will be in storefront
|
||||
LOCALE="Sk"
|
||||
# uses https://crates.io/crates/iso_currency
|
||||
|
|
1731
Cargo.lock
generated
1731
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -35,7 +35,7 @@ iso_currency = { version = "0.4.4", features = ["with-serde", "iterator"] }
|
|||
pulldown-cmark = "0.11.0"
|
||||
http = "1"
|
||||
thiserror = "1.0.61"
|
||||
wasm-bindgen = "=0.2.92"
|
||||
wasm-bindgen = "=0.2.93"
|
||||
console_error_panic_hook = "0.1"
|
||||
leptos = { version = "0.6", features = ["nightly"] }
|
||||
leptos_axum = { version = "0.6" }
|
||||
|
|
|
@ -31,8 +31,8 @@ dependencies = [
|
|||
[tasks.push-containers]
|
||||
workspace = false
|
||||
script = '''
|
||||
docker push ghcr.io/djkato/saleor-sitemap-generator:latest
|
||||
docker push ghcr.io/djkato/saleor-simple-payment-gateway:latest
|
||||
docker push ghcr.io/djkato/saleor-app-sitemap-generator:latest
|
||||
docker push ghcr.io/djkato/saleor-app-simple-payment-gateway:latest
|
||||
'''
|
||||
|
||||
[tasks.delete-images]
|
||||
|
|
|
@ -36,17 +36,28 @@ http = { workspace = true }
|
|||
pulldown-cmark = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
saleor-app-sdk = { workspace = true, features = ["bridge"], optional = true }
|
||||
dotenvy = { workspace = true }
|
||||
envy = { workspace = true }
|
||||
cynic = { workspace = true, features = ["http-surf"], optional = true }
|
||||
surf = { 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]
|
||||
cynic-codegen = { workspace = true, optional = true }
|
||||
|
||||
|
||||
[features]
|
||||
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
|
||||
ssr = [
|
||||
"dep:axum",
|
||||
"dep:tokio",
|
||||
|
@ -55,6 +66,11 @@ ssr = [
|
|||
"dep:leptos_axum",
|
||||
"dep:tracing",
|
||||
"dep:saleor-app-sdk",
|
||||
"saleor-app-sdk/file_apl",
|
||||
"saleor-app-sdk/redis_apl",
|
||||
"saleor-app-sdk/tracing",
|
||||
"saleor-app-sdk/middleware",
|
||||
"saleor-app-sdk/webhook_utils",
|
||||
"dep:tracing-subscriber",
|
||||
"dep:anyhow",
|
||||
"dep:cynic",
|
||||
|
@ -64,6 +80,13 @@ ssr = [
|
|||
"leptos_meta/ssr",
|
||||
"leptos_router/ssr",
|
||||
]
|
||||
hydrate = [
|
||||
"leptos/hydrate",
|
||||
"leptos_meta/hydrate",
|
||||
"leptos_router/hydrate",
|
||||
"dep:saleor-app-sdk",
|
||||
"saleor-app-sdk/bridge",
|
||||
]
|
||||
|
||||
|
||||
# Defines a size-optimized profile for the WASM bundle in release mode
|
||||
|
@ -95,7 +118,7 @@ tailwind-input-file = "style/base.css"
|
|||
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.
|
||||
site-addr = "127.0.0.1:3000"
|
||||
site-addr = "0.0.0.0:3000"
|
||||
|
||||
# The port to use for automatic reload monitoring
|
||||
reload-port = 3001
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::error_template::{AppError, ErrorTemplate};
|
||||
use crate::routes::extensions::order_to_pdf::Pdf;
|
||||
use crate::routes::home::Home;
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
|
@ -13,7 +14,6 @@ pub struct UrlAppParams {
|
|||
pub fn App() -> impl IntoView {
|
||||
// Provides context that manages stylesheets, titles, meta tags, etc.
|
||||
provide_meta_context();
|
||||
|
||||
view! {
|
||||
<Stylesheet id="leptos" href="/pkg/saleor-app-template-ui.css" />
|
||||
|
||||
|
@ -29,6 +29,7 @@ pub fn App() -> impl IntoView {
|
|||
<main class="p-4 md:p-8 md:px-16">
|
||||
<Routes>
|
||||
<Route path="/" view=Home />
|
||||
<Route path="/extensions/order_to_pdf" view=Pdf />
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
|
|
|
@ -13,21 +13,21 @@ mod queries;
|
|||
|
||||
mod app;
|
||||
mod components;
|
||||
mod routes;
|
||||
mod error_template;
|
||||
mod routes;
|
||||
|
||||
#[tokio::main]
|
||||
#[cfg(feature = "ssr")]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
use std::sync::Arc;
|
||||
use axum::{middleware, routing::{get, post}, Router};
|
||||
use app::*;
|
||||
use axum::{
|
||||
middleware,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use fileserv::file_and_error_handler;
|
||||
use leptos::*;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use app::*;
|
||||
use fileserv::file_and_error_handler;
|
||||
use saleor_app_sdk::middleware::verify_webhook_signature::webhook_signature_verifier;
|
||||
use tokio::sync::Mutex;
|
||||
use saleor_app_sdk::{
|
||||
cargo_info,
|
||||
config::Config,
|
||||
|
@ -35,6 +35,12 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
webhooks::{AsyncWebhookEventType, WebhookManifestBuilder},
|
||||
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};
|
||||
|
||||
|
@ -49,48 +55,20 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
let saleor_app = SaleorApp::new(&config).unwrap();
|
||||
|
||||
let app_manifest = AppManifestBuilder::new(&config, cargo_info!())
|
||||
.add_webhook(
|
||||
WebhookManifestBuilder::new(&config)
|
||||
.set_query(
|
||||
r#"
|
||||
subscription QueryProductsChanged {
|
||||
event {
|
||||
... on ProductUpdated {
|
||||
product {
|
||||
... BaseProduct
|
||||
}
|
||||
}
|
||||
... on ProductCreated {
|
||||
product {
|
||||
... BaseProduct
|
||||
}
|
||||
}
|
||||
... on ProductDeleted {
|
||||
product {
|
||||
... BaseProduct
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment BaseProduct on Product {
|
||||
id
|
||||
slug
|
||||
name
|
||||
category {
|
||||
slug
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.add_async_events(vec![
|
||||
AsyncWebhookEventType::ProductCreated,
|
||||
AsyncWebhookEventType::ProductUpdated,
|
||||
AsyncWebhookEventType::ProductDeleted,
|
||||
.add_permission(AppPermission::ManageProducts)
|
||||
.add_extension(
|
||||
AppExtensionBuilder::new()
|
||||
.set_url("/extensions/order_to_pdf")
|
||||
.set_label("Order to PDF")
|
||||
.add_permissions(vec![
|
||||
AppPermission::ManageOrders,
|
||||
AppPermission::ManageProducts,
|
||||
AppPermission::ManageProductTypesAndAttributes,
|
||||
])
|
||||
.set_mount(AppExtensionMount::OrderDetailsMoreActions)
|
||||
.set_target(AppExtensionTarget::Popup)
|
||||
.build(),
|
||||
)
|
||||
.add_permission(AppPermission::ManageProducts)
|
||||
.build();
|
||||
|
||||
let app_state = AppState {
|
||||
|
@ -101,12 +79,22 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
};
|
||||
|
||||
let state_1 = app_state.clone();
|
||||
let app =
|
||||
Router::new()
|
||||
.leptos_routes_with_context(&app_state, routes,move || provide_context(state_1.clone()) , App)
|
||||
let app = Router::new()
|
||||
.leptos_routes_with_context(
|
||||
&app_state,
|
||||
routes,
|
||||
move || provide_context(state_1.clone()),
|
||||
App,
|
||||
)
|
||||
.fallback(file_and_error_handler)
|
||||
.route("/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/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))
|
||||
.with_state(app_state.clone());
|
||||
|
||||
|
@ -122,19 +110,19 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
.await?;
|
||||
tracing::debug!("listening on {}", listener.local_addr()?);
|
||||
|
||||
let _= axum::serve(listener, app.into_make_service())
|
||||
.await;
|
||||
let _ = axum::serve(listener, app.into_make_service()).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
pub fn main() {
|
||||
use saleor_app_sdk::bridge::AppBridge;
|
||||
let app_bridge = AppBridge::new(Some(true)).unwrap();
|
||||
// no client-side main function
|
||||
// unless we want this to work with e.g., Trunk for a purely client-side app
|
||||
// see lib.rs for hydration function instead
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
use saleor_app_sdk::config::Config;
|
||||
#[cfg(feature = "ssr")]
|
||||
|
@ -144,8 +132,13 @@ pub fn trace_to_std(config: &Config) -> Result<(), envy::Error> {
|
|||
|
||||
let filter = EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::DEBUG.into())
|
||||
.from_env().unwrap()
|
||||
.add_directive(format!("{}={}", env!("CARGO_PKG_NAME"), config.log_level).parse().unwrap());
|
||||
.from_env()
|
||||
.unwrap()
|
||||
.add_directive(
|
||||
format!("{}={}", env!("CARGO_PKG_NAME"), config.log_level)
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(config.log_level)
|
||||
.with_env_filter(filter)
|
||||
|
@ -154,5 +147,3 @@ pub fn trace_to_std(config: &Config) -> Result<(), envy::Error> {
|
|||
.init();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
|
1
app-template-ui/src/routes/extensions/mod.rs
Normal file
1
app-template-ui/src/routes/extensions/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod order_to_pdf;
|
9
app-template-ui/src/routes/extensions/order_to_pdf.rs
Normal file
9
app-template-ui/src/routes/extensions/order_to_pdf.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use leptos::*;
|
||||
|
||||
#[component]
|
||||
pub fn Pdf() -> impl IntoView {
|
||||
view! {
|
||||
<h1>Yello!</h1>
|
||||
<p class="italic text-lg">r#"Loading AppBridge, please wait..."#</p>
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
#[cfg(feature = "ssr")]
|
||||
pub mod api;
|
||||
pub mod extensions;
|
||||
pub mod home;
|
||||
|
|
15
sdk/.neoconf.json
Normal file
15
sdk/.neoconf.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"lspconfig": {
|
||||
"rust_analyzer": {
|
||||
"rust-analyzer.cargo.features": "all"
|
||||
/*
|
||||
use this only when working with leptos
|
||||
*/
|
||||
// "rust-analyzer.rustfmt.overrideCommand": [
|
||||
// "leptosfmt",
|
||||
// "--stdin",
|
||||
// "--rustfmt"
|
||||
// ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ tracing-subscriber = { workspace = true, optional = true }
|
|||
## Needed for bridge
|
||||
wasm-bindgen = { workspace = true, optional = true }
|
||||
serde-wasm-bindgen = { version = "0.6.5", optional = true }
|
||||
bus = { version = "2.4.1", optional = true }
|
||||
# bus = { version = "2.4.1", optional = true }
|
||||
|
||||
[dependencies.web-sys]
|
||||
optional = true
|
||||
|
@ -66,7 +66,7 @@ features = [
|
|||
[dev-dependencies]
|
||||
|
||||
[features]
|
||||
default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
|
||||
default = []
|
||||
middleware = [
|
||||
"dep:axum",
|
||||
"dep:jsonwebtoken",
|
||||
|
@ -80,7 +80,7 @@ webhook_utils = ["dep:http"]
|
|||
tracing = ["dep:tracing", "dep:tracing-subscriber"]
|
||||
bridge = [
|
||||
"dep:wasm-bindgen",
|
||||
"dep:bus",
|
||||
# "dep:bus",
|
||||
"dep:serde-wasm-bindgen",
|
||||
"dep:web-sys",
|
||||
]
|
||||
|
|
|
@ -1,65 +1,66 @@
|
|||
use crate::locales::LocaleCode;
|
||||
|
||||
use super::ThemeType;
|
||||
use bus::{Bus, BusReader};
|
||||
// use bus::{Bus, BusReader};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::EnumIter;
|
||||
// use strum_macros::EnumIter;
|
||||
// use web_sys::js_sys::Object;
|
||||
|
||||
pub struct EventChannels {
|
||||
pub handshake: Bus<PayloadHanshake>,
|
||||
pub response: Bus<PayloadResponse>,
|
||||
pub redirect: Bus<PayloadRedirect>,
|
||||
pub theme: Bus<PayloadTheme>,
|
||||
pub locale_changed: Bus<PayloadLocaleChanged>,
|
||||
pub token_refreshed: Bus<PayloadTokenRefreshed>,
|
||||
}
|
||||
// pub struct EventChannels {
|
||||
// pub handshake: Bus<PayloadHanshake>,
|
||||
// pub response: Bus<PayloadResponse>,
|
||||
// pub redirect: Bus<PayloadRedirect>,
|
||||
// pub theme: Bus<PayloadTheme>,
|
||||
// pub locale_changed: Bus<PayloadLocaleChanged>,
|
||||
// pub token_refreshed: Bus<PayloadTokenRefreshed>,
|
||||
// }
|
||||
//
|
||||
// impl EventChannels {
|
||||
// pub fn new() -> Self {
|
||||
// Self {
|
||||
// handshake: Bus::new(10),
|
||||
// response: Bus::new(10),
|
||||
// redirect: Bus::new(10),
|
||||
// theme: Bus::new(10),
|
||||
// locale_changed: Bus::new(10),
|
||||
// token_refreshed: Bus::new(10),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_handshake(&mut self) -> BusReader<PayloadHanshake> {
|
||||
// self.handshake.add_rx()
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_response(&mut self) -> BusReader<PayloadResponse> {
|
||||
// self.response.add_rx()
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_redirect(&mut self) -> BusReader<PayloadRedirect> {
|
||||
// self.redirect.add_rx()
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_theme(&mut self) -> BusReader<PayloadTheme> {
|
||||
// self.theme.add_rx()
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_locale_changed(&mut self) -> BusReader<PayloadLocaleChanged> {
|
||||
// self.locale_changed.add_rx()
|
||||
// }
|
||||
//
|
||||
// pub fn subscribe_token_refreshed(&mut self) -> BusReader<PayloadTokenRefreshed> {
|
||||
// self.token_refreshed.add_rx()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl EventChannels {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
handshake: Bus::new(10),
|
||||
response: Bus::new(10),
|
||||
redirect: Bus::new(10),
|
||||
theme: Bus::new(10),
|
||||
locale_changed: Bus::new(10),
|
||||
token_refreshed: Bus::new(10),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subscribe_handshake(&mut self) -> BusReader<PayloadHanshake> {
|
||||
self.handshake.add_rx()
|
||||
}
|
||||
|
||||
pub fn subscribe_response(&mut self) -> BusReader<PayloadResponse> {
|
||||
self.response.add_rx()
|
||||
}
|
||||
|
||||
pub fn subscribe_redirect(&mut self) -> BusReader<PayloadRedirect> {
|
||||
self.redirect.add_rx()
|
||||
}
|
||||
|
||||
pub fn subscribe_theme(&mut self) -> BusReader<PayloadTheme> {
|
||||
self.theme.add_rx()
|
||||
}
|
||||
|
||||
pub fn subscribe_locale_changed(&mut self) -> BusReader<PayloadLocaleChanged> {
|
||||
self.locale_changed.add_rx()
|
||||
}
|
||||
|
||||
pub fn subscribe_token_refreshed(&mut self) -> BusReader<PayloadTokenRefreshed> {
|
||||
self.token_refreshed.add_rx()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(EnumIter, Debug)]
|
||||
pub enum EventType {
|
||||
Handshake,
|
||||
Response,
|
||||
Redirect,
|
||||
Theme,
|
||||
LocaleChanged,
|
||||
TokenRefreshed,
|
||||
}
|
||||
// #[derive(EnumIter, Debug)]
|
||||
// pub enum EventType {
|
||||
// Handshake,
|
||||
// Response,
|
||||
// Redirect,
|
||||
// Theme,
|
||||
// LocaleChanged,
|
||||
// TokenRefreshed,
|
||||
// }
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(tag = "type", content = "payload")]
|
||||
|
@ -71,6 +72,7 @@ pub enum Event {
|
|||
Theme(PayloadTheme),
|
||||
LocaleChanged(PayloadLocaleChanged),
|
||||
TokenRefreshed(PayloadTokenRefreshed),
|
||||
NotifyReady(String),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
|
|
@ -4,18 +4,17 @@ use std::str::FromStr;
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{EnumString, IntoStaticStr};
|
||||
use tracing::{debug, error, warn};
|
||||
use wasm_bindgen::{closure::Closure, JsCast, JsValue};
|
||||
|
||||
use crate::{locales::LocaleCode, manifest::AppPermission};
|
||||
|
||||
use self::event::{Event, EventChannels};
|
||||
use self::event::Event;
|
||||
use web_sys::console;
|
||||
|
||||
pub struct AppBridge {
|
||||
pub state: AppBridgeState,
|
||||
pub referer_origin: Option<String>,
|
||||
pub event_channels: EventChannels,
|
||||
// pub event_channels: EventChannels,
|
||||
/**
|
||||
* Should automatically emit Actions.NotifyReady.
|
||||
* If app loading time is longer, this can be disabled and sent manually.
|
||||
|
@ -77,7 +76,7 @@ impl AppBridgeState {
|
|||
state.locale = loc
|
||||
}
|
||||
}
|
||||
debug!("state from window: {:?}", &state);
|
||||
// debug!("state from window: {:?}", &state);
|
||||
console::log_1(&format!("state from window: {:?}", &state).into());
|
||||
Ok(state)
|
||||
}
|
||||
|
@ -122,10 +121,10 @@ impl Default for ThemeType {
|
|||
|
||||
impl AppBridge {
|
||||
pub fn new(auto_notify_ready: Option<bool>) -> Result<Self, AppBridgeError> {
|
||||
debug!("creating app bridge");
|
||||
// debug!("creating app bridge");
|
||||
console::log_1(&"creating app bridge".into());
|
||||
if web_sys::Window::is_type_of(&JsValue::from_str("undefined")) {
|
||||
error!("Window is undefined");
|
||||
// error!("Window is undefined");
|
||||
console::log_1(&"Window is undefined".into());
|
||||
return Err(AppBridgeError::WindowIsUndefined);
|
||||
}
|
||||
|
@ -137,7 +136,7 @@ impl AppBridge {
|
|||
})
|
||||
});
|
||||
if referrer.is_none() {
|
||||
warn!("Referrer origin is none");
|
||||
// warn!("Referrer origin is none");
|
||||
console::log_1(&"Referrer origin is none".into());
|
||||
}
|
||||
|
||||
|
@ -148,7 +147,6 @@ impl AppBridge {
|
|||
Err(e) => return Err(AppBridgeError::JsValue(e)),
|
||||
},
|
||||
referer_origin: referrer,
|
||||
event_channels: EventChannels::new(),
|
||||
};
|
||||
if bridge.auto_notify_ready.unwrap_or(false) {
|
||||
bridge.notify_ready()?;
|
||||
|
@ -161,7 +159,7 @@ impl AppBridge {
|
|||
let cb = Closure::wrap(Box::new(|e: JsValue| {
|
||||
let event_data: Result<SaleorIframeEvent, _> = serde_wasm_bindgen::from_value(e);
|
||||
web_sys::console::log_1(&format!("{:?}", &event_data).into());
|
||||
debug!("{:?}", &event_data);
|
||||
// debug!("{:?}", &event_data);
|
||||
}) as Box<dyn FnMut(_)>);
|
||||
window
|
||||
.add_event_listener_with_callback("message", &cb.as_ref().unchecked_ref())
|
||||
|
@ -182,7 +180,8 @@ impl AppBridge {
|
|||
todo!()
|
||||
}
|
||||
pub fn notify_ready(&mut self) -> Result<&mut Self, AppBridgeError> {
|
||||
todo!()
|
||||
self.dispatch_event(Event::NotifyReady("{}".to_owned()))?;
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
|
|
@ -9,6 +9,8 @@ pub mod manifest;
|
|||
pub mod middleware;
|
||||
pub mod webhooks;
|
||||
|
||||
use anyhow::bail;
|
||||
|
||||
use apl::{AplType, APL};
|
||||
use config::Config;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
58
sdk/src/manifest/extension.rs
Normal file
58
sdk/src/manifest/extension.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use super::{AppExtension, AppExtensionMount, AppExtensionTarget, AppPermission};
|
||||
|
||||
pub struct AppExtensionBuilder {
|
||||
pub extension: AppExtension,
|
||||
}
|
||||
|
||||
impl AppExtensionBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
extension: AppExtension::default(),
|
||||
}
|
||||
}
|
||||
/** Name which will be displayed in the dashboard */
|
||||
pub fn set_label(mut self, label: &str) -> Self {
|
||||
label.clone_into(&mut self.extension.label);
|
||||
self
|
||||
}
|
||||
|
||||
/** the place where the extension will be mounted */
|
||||
pub fn set_mount(mut self, mount: AppExtensionMount) -> Self {
|
||||
self.extension.mount = mount;
|
||||
self
|
||||
}
|
||||
|
||||
/** Method of presenting the interface
|
||||
`POPUP` will present the interface in a modal overlay
|
||||
`APP_PAGE` will navigate to the application page
|
||||
@default `POPUP`
|
||||
*/
|
||||
pub fn set_target(mut self, target: AppExtensionTarget) -> Self {
|
||||
self.extension.target = target;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_permission(mut self, permission: AppPermission) -> Self {
|
||||
self.extension.permissions.push(permission);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_permissions(mut self, mut permission: Vec<AppPermission>) -> Self {
|
||||
self.extension.permissions.append(&mut permission);
|
||||
self
|
||||
}
|
||||
|
||||
/** URL of the view to display,
|
||||
you can skip the domain and protocol when target is set to `APP_PAGE`, or when your manifest defines an `appUrl`.
|
||||
|
||||
When target is set to `POPUP`, the url will be used to render an `<iframe>`.
|
||||
*/
|
||||
pub fn set_url(mut self, url: &str) -> Self {
|
||||
url.clone_into(&mut self.extension.url);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> AppExtension {
|
||||
self.extension
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
pub mod extension;
|
||||
|
||||
use crate::{config::Config, webhooks::WebhookManifest};
|
||||
|
||||
|
@ -47,6 +48,11 @@ pub enum AppExtensionMount {
|
|||
OrderOverviewCreate,
|
||||
OrderOverviewMoreActions,
|
||||
}
|
||||
impl Default for AppExtensionMount {
|
||||
fn default() -> Self {
|
||||
Self::ProductOverviewMoreActions
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
|
@ -54,8 +60,13 @@ pub enum AppExtensionTarget {
|
|||
Popup,
|
||||
AppPage,
|
||||
}
|
||||
impl Default for AppExtensionTarget {
|
||||
fn default() -> Self {
|
||||
Self::Popup
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AppExtension {
|
||||
/** Name which will be displayed in the dashboard */
|
||||
|
@ -188,6 +199,20 @@ impl AppManifestBuilder {
|
|||
self.manifest.permissions.append(&mut permissions);
|
||||
self
|
||||
}
|
||||
pub fn add_extension(mut self, extension: AppExtension) -> Self {
|
||||
match &mut self.manifest.extensions {
|
||||
Some(e) => e.push(extension),
|
||||
None => self.manifest.extensions = Some(vec![extension]),
|
||||
}
|
||||
self
|
||||
}
|
||||
pub fn add_extensions(mut self, mut extensions: Vec<AppExtension>) -> Self {
|
||||
match &mut self.manifest.extensions {
|
||||
Some(e) => e.append(&mut extensions),
|
||||
None => self.manifest.extensions = Some(extensions),
|
||||
}
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> AppManifest {
|
||||
self.manifest
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
|
1
sitemap-generator/db.cbor
Normal file
1
sitemap-generator/db.cbor
Normal file
File diff suppressed because one or more lines are too long
109799
sitemap-generator/db.json
Normal file
109799
sitemap-generator/db.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,6 @@ use std::{
|
|||
fs::{self},
|
||||
io::ErrorKind,
|
||||
};
|
||||
use tinytemplate::TinyTemplate;
|
||||
|
||||
use crate::{
|
||||
app::{AppState, SitemapConfig},
|
||||
|
@ -316,12 +315,8 @@ async fn update_or_create<T: Serialize + Clone>(
|
|||
for affected in affected_urls.iter_mut() {
|
||||
match affected {
|
||||
AffectedType::Data(url) => {
|
||||
match Url::new(
|
||||
data.clone(),
|
||||
&sitemap_config,
|
||||
item.clone(),
|
||||
rel_item.clone(),
|
||||
) {
|
||||
match Url::new(data.clone(), sitemap_config, item.clone(), rel_item.clone())
|
||||
{
|
||||
Ok(new_url) => {
|
||||
url.url = new_url.url;
|
||||
url.data = new_url.data;
|
||||
|
@ -338,7 +333,7 @@ async fn update_or_create<T: Serialize + Clone>(
|
|||
let new_data: ProductCreated = url.clone().into();
|
||||
match Url::new(
|
||||
new_data,
|
||||
&sitemap_config,
|
||||
sitemap_config,
|
||||
url.clone().data,
|
||||
Some(item.clone()),
|
||||
) {
|
||||
|
@ -354,7 +349,7 @@ async fn update_or_create<T: Serialize + Clone>(
|
|||
let new_data: CollectionCreated = url.clone().into();
|
||||
match Url::new(
|
||||
new_data,
|
||||
&sitemap_config,
|
||||
sitemap_config,
|
||||
url.clone().data,
|
||||
Some(item.clone()),
|
||||
) {
|
||||
|
@ -370,7 +365,7 @@ async fn update_or_create<T: Serialize + Clone>(
|
|||
let new_data: PageCreated = url.clone().into();
|
||||
match Url::new(
|
||||
new_data,
|
||||
&sitemap_config,
|
||||
sitemap_config,
|
||||
url.clone().data,
|
||||
Some(item.clone()),
|
||||
) {
|
||||
|
@ -386,7 +381,7 @@ async fn update_or_create<T: Serialize + Clone>(
|
|||
let new_data: CollectionCreated = url.clone().into();
|
||||
match Url::new(
|
||||
new_data,
|
||||
&sitemap_config,
|
||||
sitemap_config,
|
||||
url.clone().data,
|
||||
Some(item.clone()),
|
||||
) {
|
||||
|
|
|
@ -155,7 +155,11 @@ pub async fn regenerate(state: AppState, saleor_api_url: String) -> anyhow::Resu
|
|||
slug: p.slug.clone(),
|
||||
typ: ItemType::Product,
|
||||
},
|
||||
None,
|
||||
p.category.clone().map(|c| ItemData {
|
||||
id: c.id.inner().to_owned(),
|
||||
slug: c.slug,
|
||||
typ: ItemType::Category,
|
||||
}),
|
||||
) {
|
||||
Ok(u) => Some(u),
|
||||
Err(e) => {
|
||||
|
|
|
@ -4,8 +4,7 @@ use std::time::Duration;
|
|||
|
||||
use crate::{
|
||||
create_app,
|
||||
queries::event_subjects_updated::{Category, Product, ProductUpdated},
|
||||
sitemap::{ItemType, Url, UrlSet},
|
||||
sitemap::{ItemType, UrlSet},
|
||||
};
|
||||
use async_std::task::sleep;
|
||||
use axum::{
|
||||
|
@ -61,11 +60,12 @@ pub async fn app_runs_and_responses() {
|
|||
#[tokio::test]
|
||||
#[traced_test]
|
||||
#[serial]
|
||||
//TODO: This test is busted or smt
|
||||
async fn update_event_updates_correctly() {
|
||||
let mut app = init_test_app().await;
|
||||
let (_, sitemap_config) = testing_configs();
|
||||
|
||||
let mut evn = gen_random_url_set(50, &sitemap_config);
|
||||
let mut evn = gen_random_url_set(500, &sitemap_config);
|
||||
for (body, _, webhook_type) in evn.clone() {
|
||||
app = create_query(app, body, webhook_type).await;
|
||||
}
|
||||
|
@ -272,7 +272,22 @@ fn urlset_serialisation_isnt_lossy() {
|
|||
let deserialized_url_set: UrlSet = serde_cbor::de::from_slice(&file_str).unwrap();
|
||||
assert_eq!(url_set, deserialized_url_set);
|
||||
}
|
||||
//TODO: TEST UPDATES AND DELETES, UPDATING URL CREATES A NEW ENTRY INSTEAD OF EDITING PREVIOUS ONE
|
||||
|
||||
// #[rstest]
|
||||
// #[traced_test]
|
||||
// #[parallel]
|
||||
// fn desereialize_cbor() {
|
||||
// std::fs::write(
|
||||
// "db.json",
|
||||
// serde_json::to_string_pretty(
|
||||
// &serde_cbor::de::from_slice::<UrlSet>(&std::fs::read("db.cbor").unwrap()).unwrap(),
|
||||
// )
|
||||
// .unwrap(),
|
||||
// )
|
||||
// .unwrap();
|
||||
//
|
||||
// // assert_eq!(url_set, deserialized_url_set);
|
||||
// }
|
||||
|
||||
// #[rstest]
|
||||
// #[traced_test]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use axum::{
|
||||
body::Body,
|
||||
http::{Request, Response, StatusCode},
|
||||
http::{Request, StatusCode},
|
||||
routing::RouterIntoService,
|
||||
};
|
||||
use rand::{
|
||||
|
@ -261,11 +261,35 @@ pub fn gen_random_url_set(
|
|||
) -> Vec<(String, Url, EitherWebhookType)> {
|
||||
let mut res: Vec<(String, Url, EitherWebhookType)> = vec![];
|
||||
for _ in 0..len {
|
||||
let slug = random_word::gen(random_word::Lang::En).to_owned();
|
||||
let id = cynic::Id::new(slug.to_owned() + "_ID");
|
||||
let slug = random_word::gen(random_word::Lang::En).to_owned()
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En);
|
||||
let id = cynic::Id::new("ID_".to_owned() + &slug.clone());
|
||||
|
||||
let mut rel_slug = random_word::gen(random_word::Lang::En).to_owned();
|
||||
let mut rel_id = cynic::Id::new(rel_slug.to_owned() + "_ID");
|
||||
let mut rel_slug = random_word::gen(random_word::Lang::En).to_owned()
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En)
|
||||
+ "_"
|
||||
+ random_word::gen(random_word::Lang::En);
|
||||
let mut rel_id = cynic::Id::new("ID_".to_owned() + &rel_slug.clone());
|
||||
|
||||
match rand::random::<ItemType>() {
|
||||
ItemType::Product => {
|
||||
|
|
Loading…
Reference in a new issue