From 4deb90c3ca73309afbec541574937fad667680d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 01:13:40 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(topcoat):=20a=20second=20web?= =?UTF-8?q?=20crate=20wearing=20the=20new=20coat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Cargo.lock | 714 ++++++++++++++++++++++++++++- Cargo.toml | 2 +- crates/izlek-topcoat/Cargo.toml | 39 ++ crates/izlek-topcoat/build.rs | 18 + crates/izlek-topcoat/src/layout.rs | 65 +++ crates/izlek-topcoat/src/lib.rs | 7 + crates/izlek-topcoat/src/main.rs | 93 ++++ crates/izlek-topcoat/src/smtp.rs | 203 ++++++++ 9 files changed, 1140 insertions(+), 2 deletions(-) create mode 100644 crates/izlek-topcoat/Cargo.toml create mode 100644 crates/izlek-topcoat/build.rs create mode 100644 crates/izlek-topcoat/src/layout.rs create mode 100644 crates/izlek-topcoat/src/lib.rs create mode 100644 crates/izlek-topcoat/src/main.rs create mode 100644 crates/izlek-topcoat/src/smtp.rs diff --git a/.gitignore b/.gitignore index 6687e5b..43191fa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ izlek.key /config/izlek.toml CLAUDE.md +/crates/izlek-topcoat/assets diff --git a/Cargo.lock b/Cargo.lock index 477306f..64c289a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,6 +53,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.5" @@ -62,6 +74,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e76a019e91224d279006ff972f1e984179a6e9feb050adba6ce8274aef23195" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -83,6 +110,56 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + [[package]] name = "antithesis_sdk" version = "0.2.9" @@ -117,6 +194,12 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "anymap3" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5dfbc6d8d2675589ccbe4d0fd61df2419075625f8c1a62325e718e2b0049f9" + [[package]] name = "arc-swap" version = "1.9.2" @@ -263,7 +346,7 @@ dependencies = [ "hyper", "hyper-util", "itoa", - "matchit", + "matchit 0.8.4", "memchr", "mime", "multer", @@ -448,6 +531,27 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "brotli" +version = "8.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc91aac060a7a1e25823bdccbfb6af1875b88f17c6daac97894eed8207166b3" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a32acac15fe1967bc3986b2a6347dffc965602354ea6f450ad07e8bfd253583" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.20.3" @@ -607,6 +711,33 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + [[package]] name = "cmov" version = "0.5.4" @@ -624,18 +755,31 @@ dependencies = [ "thiserror", ] +[[package]] +name = "codemap" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" + [[package]] name = "collection_literals" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2550f75b8cfac212855f6b1885455df8eaee8fe8e246b647d69146142e016084" +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + [[package]] name = "compression-codecs" version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce2548391e9c1929c21bf6aa2680af86fe4c1b33e6cea9ac1cfeec0bd11218cf" dependencies = [ + "brotli", "compression-core", "flate2", "memchr", @@ -745,6 +889,24 @@ dependencies = [ "convert_case 0.11.0", ] +[[package]] +name = "cookie" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87" +dependencies = [ + "aes-gcm", + "base64 0.22.1", + "hkdf", + "hmac", + "percent-encoding", + "rand 0.8.8", + "sha2 0.10.9", + "subtle", + "time", + "version_check", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -939,6 +1101,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common 0.1.7", + "subtle", ] [[package]] @@ -992,6 +1155,15 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "elsa" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9abf33c656a7256451ebb7d0082c5a471820c31269e49d807c538c252352186e" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "email-encoding" version = "0.4.2" @@ -1391,12 +1563,66 @@ dependencies = [ "web-sys", ] +[[package]] +name = "grass" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a68216437ef68f0738e48d6c7bb9e6e6a92237e001b03d838314b068f33c94" +dependencies = [ + "clap", + "getrandom 0.2.17", + "grass_compiler", +] + +[[package]] +name = "grass_compiler" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d9e3df7f0222ce5184154973d247c591d9aadc28ce7a73c6cd31100c9facff6" +dependencies = [ + "codemap", + "indexmap", + "lasso", + "once_cell", + "phf", + "rand 0.8.8", +] + [[package]] name = "guardian" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17e2ac29387b1aa07a1e448f7bb4f35b500787971e965b02842b900afa5c8f6f" +[[package]] +name = "h2" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8e5e5a340588f4452631496976cf8636d4a7ecf600239fdc27615d2530bc16" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2 0.2.21", +] + [[package]] name = "hashbrown" version = "0.16.1" @@ -1432,6 +1658,24 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "home" version = "0.5.12" @@ -1441,6 +1685,17 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "hostname" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" +dependencies = [ + "cfg-if", + "libc", + "windows-link", +] + [[package]] name = "html-escape" version = "0.2.15" @@ -1538,6 +1793,7 @@ dependencies = [ "bytes", "futures-channel", "futures-core", + "h2", "http", "http-body", "httparse", @@ -1823,6 +2079,12 @@ dependencies = [ "libc", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "itertools" version = "0.12.1" @@ -1868,6 +2130,21 @@ dependencies = [ "uuid", ] +[[package]] +name = "izlek-topcoat" +version = "0.1.0" +dependencies = [ + "async-trait", + "grass", + "izlek-core", + "lettre", + "serde", + "thiserror", + "time", + "tokio", + "topcoat", +] + [[package]] name = "izlek-web" version = "0.1.0" @@ -1930,6 +2207,15 @@ version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" +[[package]] +name = "lasso" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e14eda50a3494b3bf7b9ce51c52434a761e383d7238ce1dd5dcec2fbc13e9fb" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -2179,6 +2465,7 @@ dependencies = [ "fastrand", "futures-io", "futures-util", + "hostname", "httpdate", "idna", "mime", @@ -2355,6 +2642,12 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" +[[package]] +name = "matchit" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608" + [[package]] name = "measure_time" version = "0.9.0" @@ -2569,6 +2862,12 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "oneshot" version = "0.1.13" @@ -2694,6 +2993,48 @@ dependencies = [ "getrandom 0.4.3", ] +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared", + "rand 0.8.8", +] + +[[package]] +name = "phf_macros" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.13" @@ -2809,6 +3150,15 @@ dependencies = [ "syn 3.0.4", ] +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro-error-attr2" version = "2.0.0" @@ -3119,6 +3469,26 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ref-cast" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.4", +] + [[package]] name = "regex" version = "1.13.1" @@ -4093,6 +4463,7 @@ dependencies = [ "bytes", "futures-core", "futures-sink", + "libc", "pin-project-lite", "tokio", ] @@ -4121,6 +4492,18 @@ dependencies = [ "serde_core", ] +[[package]] +name = "toml_edit" +version = "0.25.13+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6975367e4d2ef766d86af01ffad14b622fecc8d4357a998fbc4deb6e9bacaf9b" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + [[package]] name = "toml_parser" version = "1.1.3+spec-1.1.0" @@ -4136,6 +4519,319 @@ version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" +[[package]] +name = "topcoat" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050c11e7b0e146a2b1eb15855abd5fa03e2754eb880922f8b6cab5ec71cac5aa" +dependencies = [ + "futures-util", + "inventory", + "serde", + "serde_urlencoded", + "tokio", + "tokio-tungstenite", + "topcoat-asset", + "topcoat-cookie", + "topcoat-core", + "topcoat-core-macro", + "topcoat-font", + "topcoat-font-macro", + "topcoat-mail", + "topcoat-router", + "topcoat-router-macro", + "topcoat-runtime", + "topcoat-runtime-macro", + "topcoat-session", + "topcoat-view", + "topcoat-view-macro", +] + +[[package]] +name = "topcoat-asset" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a72e4ba8cb6a9d29613a25c2151e72d887b4a79b3f179b497734eed0e65ea702" +dependencies = [ + "http", + "memchr", + "serde", + "sha2 0.11.0", + "thiserror", + "tokio", + "toml", + "topcoat-core", + "topcoat-router", + "topcoat-view", +] + +[[package]] +name = "topcoat-cookie" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f68c83654c4bf075f667d39463cd38ef0be9fee057054454b06612efe16e7a37" +dependencies = [ + "cookie", + "getrandom 0.2.17", + "http", + "serde", + "serde_json", + "topcoat-core", + "topcoat-router", +] + +[[package]] +name = "topcoat-core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f94adaa301d7a4b949d650fa803323c00cc8ffa8bf1984511c1ec5d390b6c6" +dependencies = [ + "anyhow", + "anymap3", + "elsa", + "http", + "pin-project-lite", + "siphasher", + "thiserror", + "tokio", +] + +[[package]] +name = "topcoat-core-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0756aa9285794c155624494bc563d56859e35205313db883a89d7dabfa6d0393" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "topcoat-core-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4908dba6268c8592be73e9059cdefa053066e1b1bc879c1c9a5d8d3b6e97aad" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-core-grammar", +] + +[[package]] +name = "topcoat-font" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7b8308aff65f46bbe2f58371fc9823db596236bd0ea3c9d87de6534fd977e60" +dependencies = [ + "heck", + "inventory", + "serde", + "serde_json", + "topcoat-asset", + "topcoat-core", + "topcoat-router", + "topcoat-view", + "topcoat-view-macro", +] + +[[package]] +name = "topcoat-font-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b7d68e226827fb7531d0dba69cb74fa7b82515f8428fd1a75f556f5a2bf87c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-font", +] + +[[package]] +name = "topcoat-font-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e655c430bcb380f879603ea750c6222ade2ff3ade33869d9eaa32e3fc49f5469" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-font-grammar", +] + +[[package]] +name = "topcoat-mail" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "959c9c32172ad3840f94c589a29bd143c072661c9abf2215a68fd76440ed2300" +dependencies = [ + "lettre", + "thiserror", + "time", + "topcoat-core", + "topcoat-router", + "topcoat-view", +] + +[[package]] +name = "topcoat-router" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e062bd348df5647f6904f4f4045b3c92c08c4a8826196e8e91a51aade00b5764" +dependencies = [ + "bytes", + "form_urlencoded", + "futures-core", + "futures-util", + "heck", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "inventory", + "matchit 0.9.2", + "multer", + "percent-encoding", + "ref-cast", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "tokio", + "topcoat-core", + "topcoat-view", + "tower", + "tower-http 0.7.0", +] + +[[package]] +name = "topcoat-router-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c052423d2aa4039036f1ac5567d1e2dac48897602d34561b3024a87830e5bdce" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", +] + +[[package]] +name = "topcoat-router-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea98692b786bab3adda35a60d71981f60b2a98c6e7105ac92e582b7c9ce9cab" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-router-grammar", +] + +[[package]] +name = "topcoat-runtime" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dea200c86ca554bab7410f09cae8790a8adcbfd8f306eb78db7092ca71f8aae" +dependencies = [ + "inventory", + "ref-cast", + "serde", + "serde_json", + "topcoat-asset", + "topcoat-core", + "topcoat-router", + "topcoat-view", + "uuid", +] + +[[package]] +name = "topcoat-runtime-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87b73f7e4e10f49e006a71dd43e8ee629c76c08451acbc51faa7ec5b6952c53c" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-runtime", + "uuid", +] + +[[package]] +name = "topcoat-runtime-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc3e4e245abcaea6af780437cae072e8f2157c9852ec5b3058a658c61b9e0bf" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-runtime-grammar", +] + +[[package]] +name = "topcoat-session" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079e8c5a63987d7f929ab05a75922feab1fe390a9cfa2c101eb35829e67eac2" +dependencies = [ + "base64 0.22.1", + "getrandom 0.4.3", + "sha2 0.11.0", + "thiserror", + "tokio", + "topcoat-cookie", + "topcoat-core", + "topcoat-router", + "web-time", +] + +[[package]] +name = "topcoat-view" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5904449bd6f633759d187fa621ded68178b551428c297959fd53d8fb91f3e6f6" +dependencies = [ + "futures-core", + "futures-util", + "http", + "itoa", + "memchr", + "pin-project-lite", + "smallvec", + "topcoat-core", +] + +[[package]] +name = "topcoat-view-grammar" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf4293156d7c5fa7960edc573b686eb27426dcd888bfbe9e532304178cdda24" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", + "topcoat-core-grammar", + "topcoat-view", +] + +[[package]] +name = "topcoat-view-macro" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58ab2b200eda4516abdb543f307006d83fedd3681b871d2042c17106c688f716" +dependencies = [ + "quote", + "syn 2.0.119", + "topcoat-view-grammar", +] + [[package]] name = "tower" version = "0.5.3" @@ -4652,6 +5348,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.25.0" @@ -4802,6 +5504,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" version = "1.0.9" diff --git a/Cargo.toml b/Cargo.toml index ac070a1..e21fdf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "3" -members = ["crates/izlek-core", "crates/izlek-web"] +members = ["crates/izlek-core", "crates/izlek-web", "crates/izlek-topcoat"] [workspace.package] version = "0.1.0" diff --git a/crates/izlek-topcoat/Cargo.toml b/crates/izlek-topcoat/Cargo.toml new file mode 100644 index 0000000..fa06dc4 --- /dev/null +++ b/crates/izlek-topcoat/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "izlek-topcoat" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description = "Izlek web app: topcoat UI, routes and the server" + +[dependencies] +topcoat = { version = "0.6.2", default-features = false, features = [ + "router", + "view", + "runtime", + "asset", + "cookie", + "discover", + "serve", + "compression", + "multipart", +] } +izlek-core = { workspace = true, features = ["server"] } +serde.workspace = true +time.workspace = true +thiserror.workspace = true +tokio = { workspace = true } +async-trait = "0.1.92" +# TLS through rustls with the ring provider: no OpenSSL on the deployment box, +# and no system certificate store to be missing inside a container. +lettre = { version = "0.11.23", default-features = false, features = [ + "smtp-transport", + "builder", + "tokio1-rustls", + "ring", + "webpki-roots", + "pool", +] } + +[build-dependencies] +grass = "0.13" diff --git a/crates/izlek-topcoat/build.rs b/crates/izlek-topcoat/build.rs new file mode 100644 index 0000000..000d655 --- /dev/null +++ b/crates/izlek-topcoat/build.rs @@ -0,0 +1,18 @@ +//! Compiles `style/main.scss` to `assets/main.css` under this crate's +//! manifest directory, where `asset!("assets/main.css")` in `layout.rs` +//! expects to find it. Crate-relative rather than `OUT_DIR`-relative so the +//! asset's id does not churn with every profile/build-hash (see the topcoat +//! contract sheet, (a)). + +fn main() { + let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let scss = format!("{manifest_dir}/../../style/main.scss"); + println!("cargo:rerun-if-changed={scss}"); + + let css = grass::from_path(&scss, &grass::Options::default()) + .unwrap_or_else(|err| panic!("failed to compile {scss}: {err}")); + + let out_dir = format!("{manifest_dir}/assets"); + std::fs::create_dir_all(&out_dir).expect("failed to create assets/"); + std::fs::write(format!("{out_dir}/main.css"), css).expect("failed to write assets/main.css"); +} diff --git a/crates/izlek-topcoat/src/layout.rs b/crates/izlek-topcoat/src/layout.rs new file mode 100644 index 0000000..8c2cd0c --- /dev/null +++ b/crates/izlek-topcoat/src/layout.rs @@ -0,0 +1,65 @@ +//! The document shell every page renders inside, ported from +//! `izlek-web/src/app.rs`'s `shell`/`App`/`NotFound`. + +use topcoat::{ + Result, + asset::{Asset, asset}, + router::{ + StatusCode, layout, page, + error::{NotFoundError, not_found}, + }, + view::view, +}; + +/// Placeholder landing page — the real board view lands in a later slice. +#[page("/")] +async fn landing() -> Result { + view! {

"Izlek"

} +} + +/// Every path that matches no page raises a `NotFoundError`, so it renders +/// through `root_layout`'s catch below rather than the router's bare default. +/// `/` itself is served by `landing` above and never reaches this route. +#[page("/{*path}")] +async fn missing() -> Result { + Err(not_found().into()) +} + +/// `style/main.scss`, compiled by `build.rs` into `assets/main.css`. +const STYLE: Asset = asset!("assets/main.css"); + +#[layout("/")] +async fn root_layout(slot: Result) -> Result { + let content = match slot { + Err(error) if error.downcast_ref::().is_some() => view! { + (StatusCode::NOT_FOUND) +
+

"Nothing at this address."

+
+ }, + content => content, + }?; + + view! { + + + + + + + + + "Izlek" + + topcoat::runtime::script() + topcoat::dev::script() + + + (content) + + + } +} diff --git a/crates/izlek-topcoat/src/lib.rs b/crates/izlek-topcoat/src/lib.rs new file mode 100644 index 0000000..2ef9765 --- /dev/null +++ b/crates/izlek-topcoat/src/lib.rs @@ -0,0 +1,7 @@ +// topcoat's `view!` nests as deeply as leptos's did for the same pages, so +// the raised limit carries over from day one rather than waiting for the +// first overflow. +#![recursion_limit = "256"] + +pub mod layout; +pub mod smtp; diff --git a/crates/izlek-topcoat/src/main.rs b/crates/izlek-topcoat/src/main.rs new file mode 100644 index 0000000..03d931c --- /dev/null +++ b/crates/izlek-topcoat/src/main.rs @@ -0,0 +1,93 @@ +use izlek_core::accounts::Accounts; +use izlek_core::store::TursoStore; +use std::sync::Arc; +use topcoat::Result; +use topcoat::asset::{AssetBundle, RouterBuilderAssetExt}; +use topcoat::cookie::RouterBuilderCookieExt; +use topcoat::router::{Router, RouterBuilderDiscoverExt, route}; + +#[route(GET "/healthz")] +async fn healthz() -> Result<&'static str> { + Ok("ok") +} + +#[tokio::main] +async fn main() { + // config/izlek.toml is read here, before anything is opened, and written with + // development defaults if it is not there yet. A broken key stops the + // boot with its name in the message: the failure this prevents is not an + // empty database, it is a second Izlek writing a different file while + // everyone believes they share a board. + let config = match izlek_core::Config::load() { + Ok(config) => config, + Err(problem) => { + eprintln!("izlek: {problem}"); + std::process::exit(2); + } + }; + // Said once, so the answer to "which file are we on" lives in the log. + for line in config.report() { + println!("izlek {line}"); + } + + // One process per database file: Turso is a single-writer engine and a + // second process on the same file loses writes rather than queueing. + // + // `open` applies any unapplied migration before it returns. + let store = TursoStore::open(&config.database.to_string_lossy()) + .await + .expect("failed to open the database"); + let store: Arc = Arc::new(store); + let accounts = Accounts::new(store.clone(), config.base_url.clone()); + + // The engine is always built, because a sender can appear at any moment: + // an admin fills the panel in and the next sweep sends what was held. It + // holds one connection pool, rebuilt only when the settings behind it + // change, and two things use it — every committed crossing, and the sweep. + let engine = Arc::new(izlek_core::MailEngine::new( + store.clone(), + Arc::new(izlek_topcoat::smtp::WorkspaceSmtp::new(store.clone())), + config.base_url.clone(), + )); + tokio::spawn(sweep(engine.clone())); + + let router = Router::builder() + .discover() + .cookies() + .assets(AssetBundle::load().expect("failed to load the asset bundle")) + .app_context(accounts) + .app_context(engine) + .build(); + + topcoat::start(router).await.expect("server error"); +} + +/// Retries what a mail server refused earlier and picks up anything a crash +/// left claimed but unsent. +/// +/// A minute is short enough that the first retry of a host that blinked lands +/// while somebody is still looking at the board, and long enough that a host +/// which is properly down is not hammered — the wait per send widens on its +/// own, and a send that has used its attempts is written off rather than +/// carried forever. +async fn sweep(engine: std::sync::Arc) { + /// Enough that a morning's backlog clears in a few passes, few enough that + /// one pass cannot sit on the mail server for minutes. + const PER_PASS: u32 = 50; + + let mut every_minute = tokio::time::interval(std::time::Duration::from_secs(60)); + loop { + every_minute.tick().await; + match engine + .deliver_owed(time::OffsetDateTime::now_utc(), PER_PASS) + .await + { + Ok(report) if report.sent + report.failed + report.abandoned > 0 => println!( + "izlek mail sweep: {} sent, {} to retry, {} given up on", + report.sent, report.failed, report.abandoned + ), + Ok(_) => {} + Err(problem) => eprintln!("izlek mail sweep could not read the ledger: {problem}"), + } + } +} diff --git a/crates/izlek-topcoat/src/smtp.rs b/crates/izlek-topcoat/src/smtp.rs new file mode 100644 index 0000000..2768e3d --- /dev/null +++ b/crates/izlek-topcoat/src/smtp.rs @@ -0,0 +1,203 @@ +//! The `Mailer` the engine talks to when the mail is real. +//! +//! Everything about SMTP stops here. The engine knows a send was accepted or +//! refused, and whether the refusal is worth trying again; it does not know +//! what a 550 is. Keeping the protocol in one file is also what makes the +//! engine testable — the tests hand it a mailer that remembers instead of +//! connecting. +//! +//! The credentials come from the workspace's own settings, written by an admin +//! on the Settings screen. They are never in a literal in here, and the +//! password is not in anything this module logs or puts in an error message: a +//! refusal that quoted the password would put it in the ledger, where an admin +//! screen would later print it. +//! +//! Because the sender is editable while the process runs, the transport cannot +//! be built once at boot. [`WorkspaceSmtp`] holds the last one it built and the +//! settings it was built from; a send whose settings still match reuses the +//! connection pool, and a send after an edit builds a new one and drops the old. + +use std::sync::Arc; + +use izlek_core::store::Store; +use izlek_core::mail::{MailError, Mailer, Outgoing}; +use lettre::message::header::ContentType; +use lettre::transport::smtp::authentication::Credentials; +use lettre::{AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor}; + +/// The sender as the mailer needs it: what the admin typed, password included. +/// It exists only inside this module and inside the store; nothing that can +/// reach a response body holds one. +#[derive(Clone, PartialEq, Eq)] +pub struct Sending { + pub host: String, + pub port: u16, + pub username: String, + pub password: String, + /// `Name
` if a name was given, the bare address otherwise. + pub from: String, +} + +/// A sender holding one connection pool. +pub struct Smtp { + transport: AsyncSmtpTransport, + from: String, +} + +impl Smtp { + /// Builds the transport. Fails only on a host name TLS cannot be set up + /// against — a server that is merely unreachable is discovered per send, + /// as a retryable refusal, which is the honest place for it. + pub fn new(mail: &Sending) -> Result { + // 465 is submissions, where TLS is up before the greeting. Everything + // else — 587 above all — is submission, where the session starts in + // the clear and is upgraded. Both are encrypted before the password + // moves; a plaintext session is not among the options. + let builder = if mail.port == 465 { + AsyncSmtpTransport::::relay(&mail.host) + } else { + AsyncSmtpTransport::::starttls_relay(&mail.host) + } + .map_err(|problem| format!("{} cannot be reached over TLS: {problem}", mail.host))?; + + Ok(Self { + transport: builder + .port(mail.port) + .credentials(Credentials::new( + mail.username.clone(), + mail.password.clone(), + )) + .build(), + from: mail.from.clone(), + }) + } +} + +#[async_trait::async_trait] +impl Mailer for Smtp { + async fn send(&self, mail: &Outgoing) -> Result<(), MailError> { + let built = + Message::builder() + .from(self.from.parse().map_err(|_| { + MailError::permanent(format!("{} is not an address", self.from)) + })?) + .to(mail + .to + .parse() + .map_err(|_| MailError::permanent(format!("{} is not an address", mail.to)))?) + .subject(&mail.subject) + .header(ContentType::TEXT_PLAIN) + .body(mail.body.clone()) + .map_err(|problem| MailError::permanent(problem.to_string()))?; + + self.transport + .send(built) + .await + .map(|_| ()) + .map_err(|problem| { + let said = problem.to_string(); + // A permanent SMTP code is the server saying the address will not + // work today or tomorrow — a mailbox that does not exist, a domain + // that does not accept us. Everything else, a timeout above all, + // is worth another attempt: the alternative is losing a mail + // because a host restarted at the wrong moment. + if problem.is_permanent() { + MailError::permanent(said) + } else { + MailError::retryable(said) + } + }) + } +} + +/// The mailer the engine actually holds: it reads the workspace's sender at +/// send time, so an admin who fixes a typo in the host does not have to restart +/// anything for the next mail to go out. +pub struct WorkspaceSmtp { + store: Arc, + /// The live transport and the settings it was built from. Rebuilt only when + /// those settings change — building one per send would throw away the + /// connection pool that makes a backlog drain quickly. + current: tokio::sync::Mutex)>>, +} + +impl WorkspaceSmtp { + pub fn new(store: Arc) -> Self { + Self { + store, + current: tokio::sync::Mutex::new(None), + } + } + + /// The sender as it stands right now, or `None` while the panel is empty. + /// + /// A half-filled sender counts as none. The screen will not save one, but + /// the check is here too, because this is the side that would otherwise + /// hand lettre an empty host and turn a missing setting into a stack of + /// refusals in the ledger. + async fn sending(&self) -> Result, MailError> { + let store = &self.store; + let workspace = store + .workspace() + .await + .map_err(|e| MailError::retryable(e.to_string()))?; + let Some(ws) = workspace else { + return Ok(None); + }; + let (Some(host), Some(port), Some(username), Some(address)) = ( + ws.smtp_host.clone(), + ws.smtp_port, + ws.smtp_username.clone(), + ws.smtp_from_address.clone(), + ) else { + return Ok(None); + }; + let password = store + .smtp_password(&ws.id) + .await + .map_err(|e| MailError::retryable(e.to_string()))?; + let (Some(password), Ok(port)) = (password, u16::try_from(port)) else { + return Ok(None); + }; + if host.trim().is_empty() || username.trim().is_empty() || password.is_empty() { + return Ok(None); + } + let from = match ws.smtp_from_name.as_deref().map(str::trim) { + Some(name) if !name.is_empty() => format!("{name} <{address}>"), + _ => address, + }; + Ok(Some(Sending { + host, + port, + username, + password, + from, + })) + } + + /// The transport for the current settings, building a new one only when + /// they have changed since the last send. + async fn transport(&self, want: &Sending) -> Result, MailError> { + let mut current = self.current.lock().await; + if let Some((held, smtp)) = current.as_ref() + && held == want + { + return Ok(smtp.clone()); + } + let built = Arc::new(Smtp::new(want).map_err(MailError::retryable)?); + *current = Some((want.clone(), built.clone())); + Ok(built) + } +} + +#[async_trait::async_trait] +impl Mailer for WorkspaceSmtp { + async fn send(&self, mail: &Outgoing) -> Result<(), MailError> { + let Some(want) = self.sending().await? else { + // Not a failure, and pointedly not an attempt: the mail is owed + // until somebody fills the sender in. + return Err(MailError::unsent("no sender configured")); + }; + self.transport(&want).await?.send(mail).await + } +}