forge
Explore
Log in

Don't you dare go Hollow

Web scaffold: boot, shell, assets, nav.js, live hub, security headers, healthz, 404

Browse files at this commit

84d70dcfe8e2217dc02c643626923fe801f9c904Ahmet Kaan GümüşParent: a4cbd4b
  • feat
    • web scaffold: boot, shell, assets, nav.js, live hub, security headers, healthz, 404
Show full message
✨ feat: web scaffold: boot, shell, assets, nav.js, live hub, security headers, healthz, 404
Cargo.lockmodified+1080 -19
@@ -57,6 +57,18 @@ dependencies = [
57 "subtle",57 "subtle",
58 ]58 ]
59 59
60+[[package]]
61+name = "ahash"
62+version = "0.8.12"
63+source = "registry+https://github.com/rust-lang/crates.io-index"
64+checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
65+dependencies = [
66+ "cfg-if",
67+ "once_cell",
68+ "version_check",
69+ "zerocopy",
70+]
71+
60 [[package]]72 [[package]]
61 name = "aho-corasick"73 name = "aho-corasick"
62 version = "1.1.5"74 version = "1.1.5"
@@ -87,6 +99,56 @@ dependencies = [
87 "libc",99 "libc",
88 ]100 ]
89 101
102+[[package]]
103+name = "anstream"
104+version = "1.0.0"
105+source = "registry+https://github.com/rust-lang/crates.io-index"
106+checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
107+dependencies = [
108+ "anstyle",
109+ "anstyle-parse",
110+ "anstyle-query",
111+ "anstyle-wincon",
112+ "colorchoice",
113+ "is_terminal_polyfill",
114+ "utf8parse",
115+]
116+
117+[[package]]
118+name = "anstyle"
119+version = "1.0.14"
120+source = "registry+https://github.com/rust-lang/crates.io-index"
121+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
122+
123+[[package]]
124+name = "anstyle-parse"
125+version = "1.0.0"
126+source = "registry+https://github.com/rust-lang/crates.io-index"
127+checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
128+dependencies = [
129+ "utf8parse",
130+]
131+
132+[[package]]
133+name = "anstyle-query"
134+version = "1.1.5"
135+source = "registry+https://github.com/rust-lang/crates.io-index"
136+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
137+dependencies = [
138+ "windows-sys 0.61.2",
139+]
140+
141+[[package]]
142+name = "anstyle-wincon"
143+version = "3.0.11"
144+source = "registry+https://github.com/rust-lang/crates.io-index"
145+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
146+dependencies = [
147+ "anstyle",
148+ "once_cell_polyfill",
149+ "windows-sys 0.61.2",
150+]
151+
90 [[package]]152 [[package]]
91 name = "antithesis_sdk"153 name = "antithesis_sdk"
92 version = "0.3.0"154 version = "0.3.0"
@@ -109,6 +171,12 @@ version = "1.0.104"
109 source = "registry+https://github.com/rust-lang/crates.io-index"171 source = "registry+https://github.com/rust-lang/crates.io-index"
110 checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"172 checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
111 173
174+[[package]]
175+name = "anymap3"
176+version = "1.1.0"
177+source = "registry+https://github.com/rust-lang/crates.io-index"
178+checksum = "fb5dfbc6d8d2675589ccbe4d0fd61df2419075625f8c1a62325e718e2b0049f9"
179+
112 [[package]]180 [[package]]
113 name = "arc-swap"181 name = "arc-swap"
114 version = "1.9.3"182 version = "1.9.3"
@@ -167,6 +235,12 @@ dependencies = [
167 "syn 3.0.9",235 "syn 3.0.9",
168 ]236 ]
169 237
238+[[package]]
239+name = "atomic-waker"
240+version = "1.1.2"
241+source = "registry+https://github.com/rust-lang/crates.io-index"
242+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
243+
170 [[package]]244 [[package]]
171 name = "autocfg"245 name = "autocfg"
172 version = "1.5.1"246 version = "1.5.1"
@@ -260,7 +334,16 @@ version = "0.11.0"
260 source = "registry+https://github.com/rust-lang/crates.io-index"334 source = "registry+https://github.com/rust-lang/crates.io-index"
261 checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f"335 checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f"
262 dependencies = [336 dependencies = [
263- "digest",337+ "digest 0.11.3",
338+]
339+
340+[[package]]
341+name = "block-buffer"
342+version = "0.10.4"
343+source = "registry+https://github.com/rust-lang/crates.io-index"
344+checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
345+dependencies = [
346+ "generic-array",
264 ]347 ]
265 348
266 [[package]]349 [[package]]
@@ -366,7 +449,7 @@ version = "0.6.0"
366 source = "registry+https://github.com/rust-lang/crates.io-index"449 source = "registry+https://github.com/rust-lang/crates.io-index"
367 checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"450 checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
368 dependencies = [451 dependencies = [
369- "nom",452+ "nom 7.1.3",
370 ]453 ]
371 454
372 [[package]]455 [[package]]
@@ -440,7 +523,7 @@ version = "0.5.2"
440 source = "registry+https://github.com/rust-lang/crates.io-index"523 source = "registry+https://github.com/rust-lang/crates.io-index"
441 checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"524 checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"
442 dependencies = [525 dependencies = [
443- "block-buffer",526+ "block-buffer 0.12.1",
444 "crypto-common 0.2.2",527 "crypto-common 0.2.2",
445 "inout 0.2.5",528 "inout 0.2.5",
446 ]529 ]
@@ -456,12 +539,51 @@ dependencies = [
456 "libloading",539 "libloading",
457 ]540 ]
458 541
542+[[package]]
543+name = "clap"
544+version = "4.6.7"
545+source = "registry+https://github.com/rust-lang/crates.io-index"
546+checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
547+dependencies = [
548+ "clap_builder",
549+]
550+
551+[[package]]
552+name = "clap_builder"
553+version = "4.6.7"
554+source = "registry+https://github.com/rust-lang/crates.io-index"
555+checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
556+dependencies = [
557+ "anstream",
558+ "anstyle",
559+ "clap_lex",
560+ "strsim",
561+]
562+
563+[[package]]
564+name = "clap_lex"
565+version = "1.1.1"
566+source = "registry+https://github.com/rust-lang/crates.io-index"
567+checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
568+
459 [[package]]569 [[package]]
460 name = "cmov"570 name = "cmov"
461 version = "0.5.4"571 version = "0.5.4"
462 source = "registry+https://github.com/rust-lang/crates.io-index"572 source = "registry+https://github.com/rust-lang/crates.io-index"
463 checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"573 checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
464 574
575+[[package]]
576+name = "codemap"
577+version = "0.1.3"
578+source = "registry+https://github.com/rust-lang/crates.io-index"
579+checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24"
580+
581+[[package]]
582+name = "colorchoice"
583+version = "1.0.5"
584+source = "registry+https://github.com/rust-lang/crates.io-index"
585+checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
586+
465 [[package]]587 [[package]]
466 name = "concurrent-queue"588 name = "concurrent-queue"
467 version = "2.5.0"589 version = "2.5.0"
@@ -477,12 +599,36 @@ version = "0.10.2"
477 source = "registry+https://github.com/rust-lang/crates.io-index"599 source = "registry+https://github.com/rust-lang/crates.io-index"
478 checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"600 checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
479 601
602+[[package]]
603+name = "cookie"
604+version = "0.18.2"
605+source = "registry+https://github.com/rust-lang/crates.io-index"
606+checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87"
607+dependencies = [
608+ "aes-gcm",
609+ "base64 0.22.1",
610+ "hkdf",
611+ "hmac",
612+ "percent-encoding",
613+ "rand 0.8.8",
614+ "sha2 0.10.9",
615+ "subtle",
616+ "time",
617+ "version_check",
618+]
619+
480 [[package]]620 [[package]]
481 name = "core-foundation-sys"621 name = "core-foundation-sys"
482 version = "0.8.7"622 version = "0.8.7"
483 source = "registry+https://github.com/rust-lang/crates.io-index"623 source = "registry+https://github.com/rust-lang/crates.io-index"
484 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"624 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
485 625
626+[[package]]
627+name = "core_detect"
628+version = "1.0.0"
629+source = "registry+https://github.com/rust-lang/crates.io-index"
630+checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
631+
486 [[package]]632 [[package]]
487 name = "cpufeatures"633 name = "cpufeatures"
488 version = "0.2.17"634 version = "0.2.17"
@@ -608,7 +754,7 @@ dependencies = [
608 "cfg-if",754 "cfg-if",
609 "cpufeatures 0.3.1",755 "cpufeatures 0.3.1",
610 "curve25519-dalek-derive",756 "curve25519-dalek-derive",
611- "digest",757+ "digest 0.11.3",
612 "fiat-crypto",758 "fiat-crypto",
613 "rand_core 0.10.1",759 "rand_core 0.10.1",
614 "rustc_version",760 "rustc_version",
@@ -661,6 +807,12 @@ dependencies = [
661 "syn 3.0.9",807 "syn 3.0.9",
662 ]808 ]
663 809
810+[[package]]
811+name = "data-encoding"
812+version = "2.11.1"
813+source = "registry+https://github.com/rust-lang/crates.io-index"
814+checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
815+
664 [[package]]816 [[package]]
665 name = "datasketches"817 name = "datasketches"
666 version = "0.2.0"818 version = "0.2.0"
@@ -676,13 +828,24 @@ dependencies = [
676 "serde_core",828 "serde_core",
677 ]829 ]
678 830
831+[[package]]
832+name = "digest"
833+version = "0.10.7"
834+source = "registry+https://github.com/rust-lang/crates.io-index"
835+checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
836+dependencies = [
837+ "block-buffer 0.10.4",
838+ "crypto-common 0.1.7",
839+ "subtle",
840+]
841+
679 [[package]]842 [[package]]
680 name = "digest"843 name = "digest"
681 version = "0.11.3"844 version = "0.11.3"
682 source = "registry+https://github.com/rust-lang/crates.io-index"845 source = "registry+https://github.com/rust-lang/crates.io-index"
683 checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"846 checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
684 dependencies = [847 dependencies = [
685- "block-buffer",848+ "block-buffer 0.12.1",
686 "const-oid",849 "const-oid",
687 "crypto-common 0.2.2",850 "crypto-common 0.2.2",
688 "ctutils",851 "ctutils",
@@ -723,7 +886,7 @@ dependencies = [
723 "curve25519-dalek",886 "curve25519-dalek",
724 "ed25519",887 "ed25519",
725 "rand_core 0.10.1",888 "rand_core 0.10.1",
726- "sha2",889+ "sha2 0.11.1",
727 "signature",890 "signature",
728 "subtle",891 "subtle",
729 "zeroize",892 "zeroize",
@@ -735,6 +898,45 @@ version = "1.19.0"
735 source = "registry+https://github.com/rust-lang/crates.io-index"898 source = "registry+https://github.com/rust-lang/crates.io-index"
736 checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"899 checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
737 900
901+[[package]]
902+name = "elsa"
903+version = "1.11.2"
904+source = "registry+https://github.com/rust-lang/crates.io-index"
905+checksum = "9abf33c656a7256451ebb7d0082c5a471820c31269e49d807c538c252352186e"
906+dependencies = [
907+ "stable_deref_trait",
908+]
909+
910+[[package]]
911+name = "email-encoding"
912+version = "0.4.2"
913+source = "registry+https://github.com/rust-lang/crates.io-index"
914+checksum = "420b9da095f052ea597503e39073b5b3c522f7db933fbac202d91d24492693fd"
915+dependencies = [
916+ "base64 0.23.1",
917+ "memchr",
918+]
919+
920+[[package]]
921+name = "email_address"
922+version = "0.2.9"
923+source = "registry+https://github.com/rust-lang/crates.io-index"
924+checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449"
925+
926+[[package]]
927+name = "encoding_rs"
928+version = "0.8.42"
929+source = "registry+https://github.com/rust-lang/crates.io-index"
930+checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"
931+dependencies = [
932+ "cfg-if",
933+ "core_detect",
934+ "multiversion_no_op",
935+ "rustversion",
936+ "scopeguard",
937+ "simdutf8",
938+]
939+
738 [[package]]940 [[package]]
739 name = "env_filter"941 name = "env_filter"
740 version = "2.0.0"942 version = "2.0.0"
@@ -835,6 +1037,15 @@ version = "0.2.0"
835 source = "registry+https://github.com/rust-lang/crates.io-index"1037 source = "registry+https://github.com/rust-lang/crates.io-index"
836 checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"1038 checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
837 1039
1040+[[package]]
1041+name = "form_urlencoded"
1042+version = "1.2.2"
1043+source = "registry+https://github.com/rust-lang/crates.io-index"
1044+checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
1045+dependencies = [
1046+ "percent-encoding",
1047+]
1048+
838 [[package]]1049 [[package]]
839 name = "fs4"1050 name = "fs4"
840 version = "0.13.1"1051 version = "0.13.1"
@@ -851,6 +1062,15 @@ version = "2.0.0"
851 source = "registry+https://github.com/rust-lang/crates.io-index"1062 source = "registry+https://github.com/rust-lang/crates.io-index"
852 checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"1063 checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
853 1064
1065+[[package]]
1066+name = "futures-channel"
1067+version = "0.3.34"
1068+source = "registry+https://github.com/rust-lang/crates.io-index"
1069+checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
1070+dependencies = [
1071+ "futures-core",
1072+]
1073+
854 [[package]]1074 [[package]]
855 name = "futures-core"1075 name = "futures-core"
856 version = "0.3.34"1076 version = "0.3.34"
@@ -868,6 +1088,12 @@ dependencies = [
868 "syn 3.0.9",1088 "syn 3.0.9",
869 ]1089 ]
870 1090
1091+[[package]]
1092+name = "futures-sink"
1093+version = "0.3.34"
1094+source = "registry+https://github.com/rust-lang/crates.io-index"
1095+checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
1096+
871 [[package]]1097 [[package]]
872 name = "futures-task"1098 name = "futures-task"
873 version = "0.3.34"1099 version = "0.3.34"
@@ -882,6 +1108,7 @@ checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
882 dependencies = [1108 dependencies = [
883 "futures-core",1109 "futures-core",
884 "futures-macro",1110 "futures-macro",
1111+ "futures-sink",
885 "futures-task",1112 "futures-task",
886 "pin-project-lite",1113 "pin-project-lite",
887 "slab",1114 "slab",
@@ -984,6 +1211,60 @@ version = "0.3.4"
984 source = "registry+https://github.com/rust-lang/crates.io-index"1211 source = "registry+https://github.com/rust-lang/crates.io-index"
985 checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"1212 checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
986 1213
1214+[[package]]
1215+name = "grass"
1216+version = "0.13.4"
1217+source = "registry+https://github.com/rust-lang/crates.io-index"
1218+checksum = "f7a68216437ef68f0738e48d6c7bb9e6e6a92237e001b03d838314b068f33c94"
1219+dependencies = [
1220+ "clap",
1221+ "getrandom 0.2.17",
1222+ "grass_compiler",
1223+]
1224+
1225+[[package]]
1226+name = "grass_compiler"
1227+version = "0.13.4"
1228+source = "registry+https://github.com/rust-lang/crates.io-index"
1229+checksum = "2d9e3df7f0222ce5184154973d247c591d9aadc28ce7a73c6cd31100c9facff6"
1230+dependencies = [
1231+ "codemap",
1232+ "indexmap",
1233+ "lasso",
1234+ "once_cell",
1235+ "phf",
1236+ "rand 0.8.8",
1237+]
1238+
1239+[[package]]
1240+name = "h2"
1241+version = "0.4.20"
1242+source = "registry+https://github.com/rust-lang/crates.io-index"
1243+checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118"
1244+dependencies = [
1245+ "atomic-waker",
1246+ "bytes",
1247+ "fnv",
1248+ "futures-core",
1249+ "futures-sink",
1250+ "http",
1251+ "indexmap",
1252+ "slab",
1253+ "tokio",
1254+ "tokio-util",
1255+ "tracing",
1256+]
1257+
1258+[[package]]
1259+name = "hashbrown"
1260+version = "0.14.5"
1261+source = "registry+https://github.com/rust-lang/crates.io-index"
1262+checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
1263+dependencies = [
1264+ "ahash",
1265+ "allocator-api2 0.2.21",
1266+]
1267+
987 [[package]]1268 [[package]]
988 name = "hashbrown"1269 name = "hashbrown"
989 version = "0.16.1"1270 version = "0.16.1"
@@ -1019,6 +1300,24 @@ version = "0.4.3"
1019 source = "registry+https://github.com/rust-lang/crates.io-index"1300 source = "registry+https://github.com/rust-lang/crates.io-index"
1020 checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"1301 checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
1021 1302
1303+[[package]]
1304+name = "hkdf"
1305+version = "0.12.4"
1306+source = "registry+https://github.com/rust-lang/crates.io-index"
1307+checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
1308+dependencies = [
1309+ "hmac",
1310+]
1311+
1312+[[package]]
1313+name = "hmac"
1314+version = "0.12.1"
1315+source = "registry+https://github.com/rust-lang/crates.io-index"
1316+checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
1317+dependencies = [
1318+ "digest 0.10.7",
1319+]
1320+
1022 [[package]]1321 [[package]]
1023 name = "home"1322 name = "home"
1024 version = "0.5.12"1323 version = "0.5.12"
@@ -1028,6 +1327,17 @@ dependencies = [
1028 "windows-sys 0.61.2",1327 "windows-sys 0.61.2",
1029 ]1328 ]
1030 1329
1330+[[package]]
1331+name = "hostname"
1332+version = "0.4.2"
1333+source = "registry+https://github.com/rust-lang/crates.io-index"
1334+checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd"
1335+dependencies = [
1336+ "cfg-if",
1337+ "libc",
1338+ "windows-link",
1339+]
1340+
1031 [[package]]1341 [[package]]
1032 name = "htmlescape"1342 name = "htmlescape"
1033 version = "0.3.1"1343 version = "0.3.1"
@@ -1044,6 +1354,41 @@ dependencies = [
1044 "itoa",1354 "itoa",
1045 ]1355 ]
1046 1356
1357+[[package]]
1358+name = "http-body"
1359+version = "1.1.0"
1360+source = "registry+https://github.com/rust-lang/crates.io-index"
1361+checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
1362+dependencies = [
1363+ "bytes",
1364+ "http",
1365+]
1366+
1367+[[package]]
1368+name = "http-body-util"
1369+version = "0.1.5"
1370+source = "registry+https://github.com/rust-lang/crates.io-index"
1371+checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
1372+dependencies = [
1373+ "bytes",
1374+ "futures-core",
1375+ "http",
1376+ "http-body",
1377+ "pin-project-lite",
1378+]
1379+
1380+[[package]]
1381+name = "httparse"
1382+version = "1.10.1"
1383+source = "registry+https://github.com/rust-lang/crates.io-index"
1384+checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
1385+
1386+[[package]]
1387+name = "httpdate"
1388+version = "1.0.3"
1389+source = "registry+https://github.com/rust-lang/crates.io-index"
1390+checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
1391+
1047 [[package]]1392 [[package]]
1048 name = "hybrid-array"1393 name = "hybrid-array"
1049 version = "0.4.15"1394 version = "0.4.15"
@@ -1053,6 +1398,41 @@ dependencies = [
1053 "typenum",1398 "typenum",
1054 ]1399 ]
1055 1400
1401+[[package]]
1402+name = "hyper"
1403+version = "1.12.0"
1404+source = "registry+https://github.com/rust-lang/crates.io-index"
1405+checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
1406+dependencies = [
1407+ "atomic-waker",
1408+ "bytes",
1409+ "futures-channel",
1410+ "futures-core",
1411+ "h2",
1412+ "http",
1413+ "http-body",
1414+ "httparse",
1415+ "httpdate",
1416+ "itoa",
1417+ "pin-project-lite",
1418+ "smallvec",
1419+ "tokio",
1420+]
1421+
1422+[[package]]
1423+name = "hyper-util"
1424+version = "0.1.21"
1425+source = "registry+https://github.com/rust-lang/crates.io-index"
1426+checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
1427+dependencies = [
1428+ "bytes",
1429+ "http",
1430+ "http-body",
1431+ "hyper",
1432+ "pin-project-lite",
1433+ "tokio",
1434+]
1435+
1056 [[package]]1436 [[package]]
1057 name = "iana-time-zone"1437 name = "iana-time-zone"
1058 version = "0.1.65"1438 version = "0.1.65"
@@ -1239,19 +1619,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1239 checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"1619 checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
1240 1620
1241 [[package]]1621 [[package]]
1242-name = "im-core"1622+name = "idna"
1243-version = "0.1.0"1623+version = "1.1.0"
1624+source = "registry+https://github.com/rust-lang/crates.io-index"
1625+checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
1244 dependencies = [1626 dependencies = [
1245- "argon2",1627+ "idna_adapter",
1246- "base64 0.23.1",1628+ "smallvec",
1247- "chacha20poly1305",1629+ "utf8_iter",
1248- "ed25519-dalek",1630+]
1249- "hex",1631+
1250- "ipnet",1632+[[package]]
1251- "rand 0.10.3",1633+name = "idna_adapter"
1252- "serde",1634+version = "1.2.2"
1635+source = "registry+https://github.com/rust-lang/crates.io-index"
1636+checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
1637+dependencies = [
1638+ "icu_normalizer",
1639+ "icu_properties",
1640+]
1641+
1642+[[package]]
1643+name = "im-core"
1644+version = "0.1.0"
1645+dependencies = [
1646+ "argon2",
1647+ "base64 0.23.1",
1648+ "chacha20poly1305",
1649+ "ed25519-dalek",
1650+ "hex",
1651+ "ipnet",
1652+ "rand 0.10.3",
1653+ "serde",
1253 "serde_json",1654 "serde_json",
1254- "sha2",1655+ "sha2 0.11.1",
1255 "subtle",1656 "subtle",
1256 "tempfile",1657 "tempfile",
1257 "thiserror",1658 "thiserror",
@@ -1266,6 +1667,20 @@ dependencies = [
1266 [[package]]1667 [[package]]
1267 name = "im-web"1668 name = "im-web"
1268 version = "0.1.0"1669 version = "0.1.0"
1670+dependencies = [
1671+ "futures-util",
1672+ "grass",
1673+ "hex",
1674+ "http",
1675+ "im-core",
1676+ "serde",
1677+ "sha2 0.11.1",
1678+ "tempfile",
1679+ "tokio",
1680+ "topcoat",
1681+ "tracing",
1682+ "tracing-subscriber",
1683+]
1269 1684
1270 [[package]]1685 [[package]]
1271 name = "indexmap"1686 name = "indexmap"
@@ -1330,6 +1745,12 @@ version = "2.12.2"
1330 source = "registry+https://github.com/rust-lang/crates.io-index"1745 source = "registry+https://github.com/rust-lang/crates.io-index"
1331 checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0"1746 checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0"
1332 1747
1748+[[package]]
1749+name = "is_terminal_polyfill"
1750+version = "1.70.2"
1751+source = "registry+https://github.com/rust-lang/crates.io-index"
1752+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
1753+
1333 [[package]]1754 [[package]]
1334 name = "itertools"1755 name = "itertools"
1335 version = "0.12.1"1756 version = "0.12.1"
@@ -1375,6 +1796,15 @@ dependencies = [
1375 "wasm-bindgen",1796 "wasm-bindgen",
1376 ]1797 ]
1377 1798
1799+[[package]]
1800+name = "lasso"
1801+version = "0.7.3"
1802+source = "registry+https://github.com/rust-lang/crates.io-index"
1803+checksum = "6e14eda50a3494b3bf7b9ce51c52434a761e383d7238ce1dd5dcec2fbc13e9fb"
1804+dependencies = [
1805+ "hashbrown 0.14.5",
1806+]
1807+
1378 [[package]]1808 [[package]]
1379 name = "lazy_static"1809 name = "lazy_static"
1380 version = "1.5.1"1810 version = "1.5.1"
@@ -1387,6 +1817,23 @@ version = "1.3.0"
1387 source = "registry+https://github.com/rust-lang/crates.io-index"1817 source = "registry+https://github.com/rust-lang/crates.io-index"
1388 checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"1818 checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
1389 1819
1820+[[package]]
1821+name = "lettre"
1822+version = "0.11.23"
1823+source = "registry+https://github.com/rust-lang/crates.io-index"
1824+checksum = "f2c646bd5cc763b1087b15493e29a64be6147ba8f19342004fa52048ee596eae"
1825+dependencies = [
1826+ "email-encoding",
1827+ "email_address",
1828+ "fastrand",
1829+ "hostname",
1830+ "httpdate",
1831+ "idna",
1832+ "mime",
1833+ "nom 8.0.0",
1834+ "quoted_printable",
1835+]
1836+
1390 [[package]]1837 [[package]]
1391 name = "levenshtein_automata"1838 name = "levenshtein_automata"
1392 version = "0.2.1"1839 version = "0.2.1"
@@ -1514,6 +1961,12 @@ dependencies = [
1514 "regex-automata",1961 "regex-automata",
1515 ]1962 ]
1516 1963
1964+[[package]]
1965+name = "matchit"
1966+version = "0.9.2"
1967+source = "registry+https://github.com/rust-lang/crates.io-index"
1968+checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608"
1969+
1517 [[package]]1970 [[package]]
1518 name = "measure_time"1971 name = "measure_time"
1519 version = "0.9.0"1972 version = "0.9.0"
@@ -1578,12 +2031,52 @@ dependencies = [
1578 "libmimalloc-sys",2031 "libmimalloc-sys",
1579 ]2032 ]
1580 2033
2034+[[package]]
2035+name = "mime"
2036+version = "0.3.17"
2037+source = "registry+https://github.com/rust-lang/crates.io-index"
2038+checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
2039+
1581 [[package]]2040 [[package]]
1582 name = "minimal-lexical"2041 name = "minimal-lexical"
1583 version = "0.2.1"2042 version = "0.2.1"
1584 source = "registry+https://github.com/rust-lang/crates.io-index"2043 source = "registry+https://github.com/rust-lang/crates.io-index"
1585 checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"2044 checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
1586 2045
2046+[[package]]
2047+name = "mio"
2048+version = "1.2.4"
2049+source = "registry+https://github.com/rust-lang/crates.io-index"
2050+checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
2051+dependencies = [
2052+ "libc",
2053+ "wasi",
2054+ "windows-sys 0.61.2",
2055+]
2056+
2057+[[package]]
2058+name = "multer"
2059+version = "3.1.0"
2060+source = "registry+https://github.com/rust-lang/crates.io-index"
2061+checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b"
2062+dependencies = [
2063+ "bytes",
2064+ "encoding_rs",
2065+ "futures-util",
2066+ "http",
2067+ "httparse",
2068+ "memchr",
2069+ "mime",
2070+ "spin",
2071+ "version_check",
2072+]
2073+
2074+[[package]]
2075+name = "multiversion_no_op"
2076+version = "1.0.0"
2077+source = "registry+https://github.com/rust-lang/crates.io-index"
2078+checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"
2079+
1587 [[package]]2080 [[package]]
1588 name = "murmurhash32"2081 name = "murmurhash32"
1589 version = "0.3.1"2082 version = "0.3.1"
@@ -1600,6 +2093,15 @@ dependencies = [
1600 "minimal-lexical",2093 "minimal-lexical",
1601 ]2094 ]
1602 2095
2096+[[package]]
2097+name = "nom"
2098+version = "8.0.0"
2099+source = "registry+https://github.com/rust-lang/crates.io-index"
2100+checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405"
2101+dependencies = [
2102+ "memchr",
2103+]
2104+
1603 [[package]]2105 [[package]]
1604 name = "nu-ansi-term"2106 name = "nu-ansi-term"
1605 version = "0.50.3"2107 version = "0.50.3"
@@ -1649,6 +2151,12 @@ version = "1.21.4"
1649 source = "registry+https://github.com/rust-lang/crates.io-index"2151 source = "registry+https://github.com/rust-lang/crates.io-index"
1650 checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"2152 checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
1651 2153
2154+[[package]]
2155+name = "once_cell_polyfill"
2156+version = "1.70.2"
2157+source = "registry+https://github.com/rust-lang/crates.io-index"
2158+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
2159+
1652 [[package]]2160 [[package]]
1653 name = "oneshot"2161 name = "oneshot"
1654 version = "0.1.13"2162 version = "0.1.13"
@@ -1733,6 +2241,12 @@ version = "0.2.3"
1733 source = "registry+https://github.com/rust-lang/crates.io-index"2241 source = "registry+https://github.com/rust-lang/crates.io-index"
1734 checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"2242 checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
1735 2243
2244+[[package]]
2245+name = "percent-encoding"
2246+version = "2.3.2"
2247+source = "registry+https://github.com/rust-lang/crates.io-index"
2248+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
2249+
1736 [[package]]2250 [[package]]
1737 name = "phc"2251 name = "phc"
1738 version = "0.6.1"2252 version = "0.6.1"
@@ -1744,6 +2258,48 @@ dependencies = [
1744 "getrandom 0.4.3",2258 "getrandom 0.4.3",
1745 ]2259 ]
1746 2260
2261+[[package]]
2262+name = "phf"
2263+version = "0.11.3"
2264+source = "registry+https://github.com/rust-lang/crates.io-index"
2265+checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
2266+dependencies = [
2267+ "phf_macros",
2268+ "phf_shared",
2269+]
2270+
2271+[[package]]
2272+name = "phf_generator"
2273+version = "0.11.3"
2274+source = "registry+https://github.com/rust-lang/crates.io-index"
2275+checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
2276+dependencies = [
2277+ "phf_shared",
2278+ "rand 0.8.8",
2279+]
2280+
2281+[[package]]
2282+name = "phf_macros"
2283+version = "0.11.3"
2284+source = "registry+https://github.com/rust-lang/crates.io-index"
2285+checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
2286+dependencies = [
2287+ "phf_generator",
2288+ "phf_shared",
2289+ "proc-macro2",
2290+ "quote",
2291+ "syn 2.0.119",
2292+]
2293+
2294+[[package]]
2295+name = "phf_shared"
2296+version = "0.11.3"
2297+source = "registry+https://github.com/rust-lang/crates.io-index"
2298+checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
2299+dependencies = [
2300+ "siphasher",
2301+]
2302+
1747 [[package]]2303 [[package]]
1748 name = "pin-project-lite"2304 name = "pin-project-lite"
1749 version = "0.2.17"2305 version = "0.2.17"
@@ -1838,6 +2394,15 @@ dependencies = [
1838 "syn 3.0.9",2394 "syn 3.0.9",
1839 ]2395 ]
1840 2396
2397+[[package]]
2398+name = "proc-macro-crate"
2399+version = "3.5.0"
2400+source = "registry+https://github.com/rust-lang/crates.io-index"
2401+checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
2402+dependencies = [
2403+ "toml_edit",
2404+]
2405+
1841 [[package]]2406 [[package]]
1842 name = "proc-macro2"2407 name = "proc-macro2"
1843 version = "1.0.107"2408 version = "1.0.107"
@@ -1879,6 +2444,12 @@ dependencies = [
1879 "proc-macro2",2444 "proc-macro2",
1880 ]2445 ]
1881 2446
2447+[[package]]
2448+name = "quoted_printable"
2449+version = "0.5.2"
2450+source = "registry+https://github.com/rust-lang/crates.io-index"
2451+checksum = "478e0585659a122aa407eb7e3c0e1fa51b1d8a870038bd29f0cf4a8551eea972"
2452+
1882 [[package]]2453 [[package]]
1883 name = "r-efi"2454 name = "r-efi"
1884 version = "5.3.0"2455 version = "5.3.0"
@@ -2020,6 +2591,26 @@ dependencies = [
2020 "bitflags",2591 "bitflags",
2021 ]2592 ]
2022 2593
2594+[[package]]
2595+name = "ref-cast"
2596+version = "1.0.27"
2597+source = "registry+https://github.com/rust-lang/crates.io-index"
2598+checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3"
2599+dependencies = [
2600+ "ref-cast-impl",
2601+]
2602+
2603+[[package]]
2604+name = "ref-cast-impl"
2605+version = "1.0.27"
2606+source = "registry+https://github.com/rust-lang/crates.io-index"
2607+checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a"
2608+dependencies = [
2609+ "proc-macro2",
2610+ "quote",
2611+ "syn 3.0.9",
2612+]
2613+
2023 [[package]]2614 [[package]]
2024 name = "regex"2615 name = "regex"
2025 version = "1.13.1"2616 version = "1.13.1"
@@ -2199,6 +2790,17 @@ dependencies = [
2199 "zmij",2790 "zmij",
2200 ]2791 ]
2201 2792
2793+[[package]]
2794+name = "serde_path_to_error"
2795+version = "0.1.20"
2796+source = "registry+https://github.com/rust-lang/crates.io-index"
2797+checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457"
2798+dependencies = [
2799+ "itoa",
2800+ "serde",
2801+ "serde_core",
2802+]
2803+
2202 [[package]]2804 [[package]]
2203 name = "serde_spanned"2805 name = "serde_spanned"
2204 version = "1.1.2"2806 version = "1.1.2"
@@ -2208,12 +2810,46 @@ dependencies = [
2208 "serde_core",2810 "serde_core",
2209 ]2811 ]
2210 2812
2813+[[package]]
2814+name = "serde_urlencoded"
2815+version = "0.7.1"
2816+source = "registry+https://github.com/rust-lang/crates.io-index"
2817+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
2818+dependencies = [
2819+ "form_urlencoded",
2820+ "itoa",
2821+ "ryu",
2822+ "serde",
2823+]
2824+
2825+[[package]]
2826+name = "sha1"
2827+version = "0.10.7"
2828+source = "registry+https://github.com/rust-lang/crates.io-index"
2829+checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8"
2830+dependencies = [
2831+ "cfg-if",
2832+ "cpufeatures 0.2.17",
2833+ "digest 0.10.7",
2834+]
2835+
2211 [[package]]2836 [[package]]
2212 name = "sha1_smol"2837 name = "sha1_smol"
2213 version = "1.0.1"2838 version = "1.0.1"
2214 source = "registry+https://github.com/rust-lang/crates.io-index"2839 source = "registry+https://github.com/rust-lang/crates.io-index"
2215 checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d"2840 checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d"
2216 2841
2842+[[package]]
2843+name = "sha2"
2844+version = "0.10.9"
2845+source = "registry+https://github.com/rust-lang/crates.io-index"
2846+checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
2847+dependencies = [
2848+ "cfg-if",
2849+ "cpufeatures 0.2.17",
2850+ "digest 0.10.7",
2851+]
2852+
2217 [[package]]2853 [[package]]
2218 name = "sha2"2854 name = "sha2"
2219 version = "0.11.1"2855 version = "0.11.1"
@@ -2222,7 +2858,7 @@ checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
2222 dependencies = [2858 dependencies = [
2223 "cfg-if",2859 "cfg-if",
2224 "cpufeatures 0.3.1",2860 "cpufeatures 0.3.1",
2225- "digest",2861+ "digest 0.11.3",
2226 ]2862 ]
2227 2863
2228 [[package]]2864 [[package]]
@@ -2266,6 +2902,16 @@ dependencies = [
2266 "tracing",2902 "tracing",
2267 ]2903 ]
2268 2904
2905+[[package]]
2906+name = "signal-hook-registry"
2907+version = "1.4.8"
2908+source = "registry+https://github.com/rust-lang/crates.io-index"
2909+checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
2910+dependencies = [
2911+ "errno",
2912+ "libc",
2913+]
2914+
2269 [[package]]2915 [[package]]
2270 name = "signature"2916 name = "signature"
2271 version = "3.0.0"2917 version = "3.0.0"
@@ -2317,12 +2963,28 @@ version = "1.16.4"
2317 source = "registry+https://github.com/rust-lang/crates.io-index"2963 source = "registry+https://github.com/rust-lang/crates.io-index"
2318 checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"2964 checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"
2319 2965
2966+[[package]]
2967+name = "socket2"
2968+version = "0.6.5"
2969+source = "registry+https://github.com/rust-lang/crates.io-index"
2970+checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
2971+dependencies = [
2972+ "libc",
2973+ "windows-sys 0.61.2",
2974+]
2975+
2320 [[package]]2976 [[package]]
2321 name = "softaes"2977 name = "softaes"
2322 version = "0.1.7"2978 version = "0.1.7"
2323 source = "registry+https://github.com/rust-lang/crates.io-index"2979 source = "registry+https://github.com/rust-lang/crates.io-index"
2324 checksum = "c4fdfe13e1c42e45f497416afb8dc4e783bf0e25b7be9077c1c77c5fb14cb998"2980 checksum = "c4fdfe13e1c42e45f497416afb8dc4e783bf0e25b7be9077c1c77c5fb14cb998"
2325 2981
2982+[[package]]
2983+name = "spin"
2984+version = "0.9.9"
2985+source = "registry+https://github.com/rust-lang/crates.io-index"
2986+checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e"
2987+
2326 [[package]]2988 [[package]]
2327 name = "stable_deref_trait"2989 name = "stable_deref_trait"
2328 version = "1.2.1"2990 version = "1.2.1"
@@ -2511,7 +3173,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2511 checksum = "dfadb8526b6da90704feb293b0701a6aae62ea14983143344be2dc5ce30f1d82"3173 checksum = "dfadb8526b6da90704feb293b0701a6aae62ea14983143344be2dc5ce30f1d82"
2512 dependencies = [3174 dependencies = [
2513 "fnv",3175 "fnv",
2514- "nom",3176+ "nom 7.1.3",
2515 "ordered-float",3177 "ordered-float",
2516 "serde",3178 "serde",
2517 "serde_json",3179 "serde_json",
@@ -2645,8 +3307,14 @@ version = "1.54.1"
2645 source = "registry+https://github.com/rust-lang/crates.io-index"3307 source = "registry+https://github.com/rust-lang/crates.io-index"
2646 checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"3308 checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
2647 dependencies = [3309 dependencies = [
3310+ "bytes",
3311+ "libc",
3312+ "mio",
2648 "pin-project-lite",3313 "pin-project-lite",
3314+ "signal-hook-registry",
3315+ "socket2",
2649 "tokio-macros",3316 "tokio-macros",
3317+ "windows-sys 0.61.2",
2650 ]3318 ]
2651 3319
2652 [[package]]3320 [[package]]
@@ -2660,6 +3328,32 @@ dependencies = [
2660 "syn 3.0.9",3328 "syn 3.0.9",
2661 ]3329 ]
2662 3330
3331+[[package]]
3332+name = "tokio-tungstenite"
3333+version = "0.29.0"
3334+source = "registry+https://github.com/rust-lang/crates.io-index"
3335+checksum = "8f72a05e828585856dacd553fba484c242c46e391fb0e58917c942ee9202915c"
3336+dependencies = [
3337+ "futures-util",
3338+ "log",
3339+ "tokio",
3340+ "tungstenite",
3341+]
3342+
3343+[[package]]
3344+name = "tokio-util"
3345+version = "0.7.20"
3346+source = "registry+https://github.com/rust-lang/crates.io-index"
3347+checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b"
3348+dependencies = [
3349+ "bytes",
3350+ "futures-core",
3351+ "futures-sink",
3352+ "libc",
3353+ "pin-project-lite",
3354+ "tokio",
3355+]
3356+
2663 [[package]]3357 [[package]]
2664 name = "toml"3358 name = "toml"
2665 version = "1.1.8+spec-1.1.0"3359 version = "1.1.8+spec-1.1.0"
@@ -2684,6 +3378,18 @@ dependencies = [
2684 "serde_core",3378 "serde_core",
2685 ]3379 ]
2686 3380
3381+[[package]]
3382+name = "toml_edit"
3383+version = "0.25.17+spec-1.1.0"
3384+source = "registry+https://github.com/rust-lang/crates.io-index"
3385+checksum = "e3641d5bbb5349a79e1020a242d251efbc546ad8048d133958323ce9c40a9c9c"
3386+dependencies = [
3387+ "indexmap",
3388+ "toml_datetime",
3389+ "toml_parser",
3390+ "winnow",
3391+]
3392+
2687 [[package]]3393 [[package]]
2688 name = "toml_parser"3394 name = "toml_parser"
2689 version = "1.1.5+spec-1.1.0"3395 version = "1.1.5+spec-1.1.0"
@@ -2699,6 +3405,336 @@ version = "1.1.3+spec-1.1.0"
2699 source = "registry+https://github.com/rust-lang/crates.io-index"3405 source = "registry+https://github.com/rust-lang/crates.io-index"
2700 checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"3406 checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"
2701 3407
3408+[[package]]
3409+name = "topcoat"
3410+version = "0.11.0"
3411+source = "registry+https://github.com/rust-lang/crates.io-index"
3412+checksum = "70b5093d8133b513742b7461a28d374107b8bf9168aa60f4f567ad89acd2ed9e"
3413+dependencies = [
3414+ "futures-util",
3415+ "inventory",
3416+ "serde",
3417+ "tokio",
3418+ "tokio-tungstenite",
3419+ "topcoat-asset",
3420+ "topcoat-cookie",
3421+ "topcoat-core",
3422+ "topcoat-core-macro",
3423+ "topcoat-font",
3424+ "topcoat-font-macro",
3425+ "topcoat-l10n",
3426+ "topcoat-mail",
3427+ "topcoat-router",
3428+ "topcoat-router-macro",
3429+ "topcoat-runtime",
3430+ "topcoat-runtime-macro",
3431+ "topcoat-session",
3432+ "topcoat-view",
3433+ "topcoat-view-macro",
3434+]
3435+
3436+[[package]]
3437+name = "topcoat-asset"
3438+version = "0.11.0"
3439+source = "registry+https://github.com/rust-lang/crates.io-index"
3440+checksum = "ac70debf9eee62714ce45416eae27b283c3a44a0f9ebcb2ac088fda48b533f3e"
3441+dependencies = [
3442+ "http",
3443+ "memchr",
3444+ "percent-encoding",
3445+ "serde",
3446+ "sha2 0.11.1",
3447+ "thiserror",
3448+ "tokio",
3449+ "toml",
3450+ "topcoat-core",
3451+ "topcoat-router",
3452+ "topcoat-view",
3453+]
3454+
3455+[[package]]
3456+name = "topcoat-cookie"
3457+version = "0.11.0"
3458+source = "registry+https://github.com/rust-lang/crates.io-index"
3459+checksum = "df79aba10192abe21fbd01dfcb46bb04dab5ae64adb4432d9f078eb05f94e6a5"
3460+dependencies = [
3461+ "cookie",
3462+ "getrandom 0.2.17",
3463+ "http",
3464+ "serde",
3465+ "serde_json",
3466+ "topcoat-core",
3467+ "topcoat-router",
3468+]
3469+
3470+[[package]]
3471+name = "topcoat-core"
3472+version = "0.11.0"
3473+source = "registry+https://github.com/rust-lang/crates.io-index"
3474+checksum = "ffff49b885744cdb89ee158c5d81cc8c619692bd9f4ab3cae92ad1adc0ce612e"
3475+dependencies = [
3476+ "anymap3",
3477+ "base64 0.22.1",
3478+ "elsa",
3479+ "http",
3480+ "pin-project-lite",
3481+ "siphasher",
3482+ "thiserror",
3483+ "tokio",
3484+]
3485+
3486+[[package]]
3487+name = "topcoat-core-grammar"
3488+version = "0.11.0"
3489+source = "registry+https://github.com/rust-lang/crates.io-index"
3490+checksum = "b788a2010234cd29fc050268e52ceb393d2124b20f669a83d8f61a9dbf895bb6"
3491+dependencies = [
3492+ "proc-macro-crate",
3493+ "proc-macro2",
3494+ "quote",
3495+ "syn 3.0.9",
3496+]
3497+
3498+[[package]]
3499+name = "topcoat-core-macro"
3500+version = "0.11.0"
3501+source = "registry+https://github.com/rust-lang/crates.io-index"
3502+checksum = "3e3786bf2ee2c8b4f728d3fb53c41f639aa66583788b3135acbd63c11458b25b"
3503+dependencies = [
3504+ "quote",
3505+ "syn 3.0.9",
3506+ "topcoat-core-grammar",
3507+]
3508+
3509+[[package]]
3510+name = "topcoat-font"
3511+version = "0.11.0"
3512+source = "registry+https://github.com/rust-lang/crates.io-index"
3513+checksum = "caa4656294aac116def1e7633f03117a84b65126c503242793ff4adc78577fb8"
3514+dependencies = [
3515+ "heck",
3516+ "inventory",
3517+ "serde",
3518+ "serde_json",
3519+ "topcoat-asset",
3520+ "topcoat-core",
3521+ "topcoat-router",
3522+ "topcoat-view",
3523+ "topcoat-view-macro",
3524+]
3525+
3526+[[package]]
3527+name = "topcoat-font-grammar"
3528+version = "0.11.0"
3529+source = "registry+https://github.com/rust-lang/crates.io-index"
3530+checksum = "b462fae28641a1bb24eab1fa9c473520389ca690331ca53fd6143d5b2746045e"
3531+dependencies = [
3532+ "proc-macro2",
3533+ "quote",
3534+ "syn 3.0.9",
3535+ "topcoat-core-grammar",
3536+ "topcoat-font",
3537+]
3538+
3539+[[package]]
3540+name = "topcoat-font-macro"
3541+version = "0.11.0"
3542+source = "registry+https://github.com/rust-lang/crates.io-index"
3543+checksum = "40776cd3087aaea5e0c8b597126b1c09dbfb0d69833088d7f3b229305bbbb87f"
3544+dependencies = [
3545+ "quote",
3546+ "syn 3.0.9",
3547+ "topcoat-font-grammar",
3548+]
3549+
3550+[[package]]
3551+name = "topcoat-l10n"
3552+version = "0.11.0"
3553+source = "registry+https://github.com/rust-lang/crates.io-index"
3554+checksum = "34da63b3a5aea3d6c243d9fa8c98ca79b181b985f6a0a042f630672f54d12e9e"
3555+dependencies = [
3556+ "icu_locale",
3557+ "icu_locale_core",
3558+ "topcoat-core",
3559+ "topcoat-view",
3560+]
3561+
3562+[[package]]
3563+name = "topcoat-mail"
3564+version = "0.11.0"
3565+source = "registry+https://github.com/rust-lang/crates.io-index"
3566+checksum = "54a13c10c6399d9eb9b0bde38bd3d947eba56ddfaea99d9a4f971b74b6a651db"
3567+dependencies = [
3568+ "lettre",
3569+ "thiserror",
3570+ "time",
3571+ "topcoat-core",
3572+ "topcoat-router",
3573+ "topcoat-view",
3574+]
3575+
3576+[[package]]
3577+name = "topcoat-router"
3578+version = "0.11.0"
3579+source = "registry+https://github.com/rust-lang/crates.io-index"
3580+checksum = "b9488065b08f293208b0f1aeb6667d5836b66c12dfced5e330f9a8f1d7f1ca1a"
3581+dependencies = [
3582+ "bytes",
3583+ "form_urlencoded",
3584+ "futures-core",
3585+ "futures-sink",
3586+ "futures-util",
3587+ "heck",
3588+ "http",
3589+ "http-body",
3590+ "http-body-util",
3591+ "hyper",
3592+ "hyper-util",
3593+ "inventory",
3594+ "ipnet",
3595+ "matchit",
3596+ "multer",
3597+ "percent-encoding",
3598+ "pin-project-lite",
3599+ "ref-cast",
3600+ "serde",
3601+ "serde_json",
3602+ "serde_path_to_error",
3603+ "serde_urlencoded",
3604+ "tokio",
3605+ "tokio-tungstenite",
3606+ "topcoat-core",
3607+ "topcoat-view",
3608+]
3609+
3610+[[package]]
3611+name = "topcoat-router-grammar"
3612+version = "0.11.0"
3613+source = "registry+https://github.com/rust-lang/crates.io-index"
3614+checksum = "ac3f51fa1a1e538bd34e02f88ebba554ac5931e55c688303a58a8e78123dfb04"
3615+dependencies = [
3616+ "heck",
3617+ "proc-macro2",
3618+ "quote",
3619+ "syn 3.0.9",
3620+ "topcoat-core-grammar",
3621+]
3622+
3623+[[package]]
3624+name = "topcoat-router-macro"
3625+version = "0.11.0"
3626+source = "registry+https://github.com/rust-lang/crates.io-index"
3627+checksum = "3c1b56d3bf19d54bddf300d6d57ca754531d7ad5481afca0b2302ac33f5d43af"
3628+dependencies = [
3629+ "quote",
3630+ "syn 3.0.9",
3631+ "topcoat-router-grammar",
3632+]
3633+
3634+[[package]]
3635+name = "topcoat-runtime"
3636+version = "0.11.0"
3637+source = "registry+https://github.com/rust-lang/crates.io-index"
3638+checksum = "03b22136b99694b349a950cd757387a04b080fdb131eecdd51d0511e1a45ebf5"
3639+dependencies = [
3640+ "futures-util",
3641+ "pin-project-lite",
3642+ "ref-cast",
3643+ "serde",
3644+ "serde_json",
3645+ "tokio",
3646+ "topcoat-asset",
3647+ "topcoat-core",
3648+ "topcoat-router",
3649+ "topcoat-view",
3650+ "topcoat-view-macro",
3651+]
3652+
3653+[[package]]
3654+name = "topcoat-runtime-grammar"
3655+version = "0.11.0"
3656+source = "registry+https://github.com/rust-lang/crates.io-index"
3657+checksum = "ab93a83c38a045a4f541c2e548d30ba5dfdd3173c18de8b1c7b049709c29db97"
3658+dependencies = [
3659+ "proc-macro2",
3660+ "quote",
3661+ "serde",
3662+ "serde_json",
3663+ "syn 3.0.9",
3664+ "topcoat-core-grammar",
3665+ "topcoat-router",
3666+ "topcoat-runtime",
3667+]
3668+
3669+[[package]]
3670+name = "topcoat-runtime-macro"
3671+version = "0.11.0"
3672+source = "registry+https://github.com/rust-lang/crates.io-index"
3673+checksum = "5acb1db0bdba3c36e4f80f7ef530945779a1b0294b1087e7d877e33005da6283"
3674+dependencies = [
3675+ "quote",
3676+ "syn 3.0.9",
3677+ "topcoat-runtime-grammar",
3678+]
3679+
3680+[[package]]
3681+name = "topcoat-session"
3682+version = "0.11.0"
3683+source = "registry+https://github.com/rust-lang/crates.io-index"
3684+checksum = "2325c30a484b1b1b6f5012b50bc18994d37c33c6bd2f71be8ff509b591a17457"
3685+dependencies = [
3686+ "base64 0.22.1",
3687+ "getrandom 0.4.3",
3688+ "sha2 0.11.1",
3689+ "thiserror",
3690+ "tokio",
3691+ "topcoat-cookie",
3692+ "topcoat-core",
3693+ "topcoat-router",
3694+ "web-time",
3695+]
3696+
3697+[[package]]
3698+name = "topcoat-view"
3699+version = "0.11.0"
3700+source = "registry+https://github.com/rust-lang/crates.io-index"
3701+checksum = "db4553b91f30e30c71c2bd95ae8e931a33326c6ffb604663b9d214008f12947c"
3702+dependencies = [
3703+ "futures-core",
3704+ "futures-util",
3705+ "http",
3706+ "memchr",
3707+ "pin-project-lite",
3708+ "siphasher",
3709+ "smallvec",
3710+ "topcoat-core",
3711+]
3712+
3713+[[package]]
3714+name = "topcoat-view-grammar"
3715+version = "0.11.0"
3716+source = "registry+https://github.com/rust-lang/crates.io-index"
3717+checksum = "75dd093ffc848370da4cce7670ccdfd4e98eab48e178d5d0da5509f747d85ca6"
3718+dependencies = [
3719+ "heck",
3720+ "proc-macro2",
3721+ "quote",
3722+ "syn 3.0.9",
3723+ "topcoat-core-grammar",
3724+ "topcoat-view",
3725+]
3726+
3727+[[package]]
3728+name = "topcoat-view-macro"
3729+version = "0.11.0"
3730+source = "registry+https://github.com/rust-lang/crates.io-index"
3731+checksum = "ffa1688d165704f08d58c03710453d0d39553292bea61b18be7959a996c3e39b"
3732+dependencies = [
3733+ "quote",
3734+ "syn 3.0.9",
3735+ "topcoat-view-grammar",
3736+]
3737+
2702 [[package]]3738 [[package]]
2703 name = "tracing"3739 name = "tracing"
2704 version = "0.1.44"3740 version = "0.1.44"
@@ -2773,6 +3809,22 @@ dependencies = [
2773 "tracing-log",3809 "tracing-log",
2774 ]3810 ]
2775 3811
3812+[[package]]
3813+name = "tungstenite"
3814+version = "0.29.0"
3815+source = "registry+https://github.com/rust-lang/crates.io-index"
3816+checksum = "6c01152af293afb9c7c2a57e4b559c5620b421f6d133261c60dd2d0cdb38e6b8"
3817+dependencies = [
3818+ "bytes",
3819+ "data-encoding",
3820+ "http",
3821+ "httparse",
3822+ "log",
3823+ "rand 0.9.5",
3824+ "sha1",
3825+ "thiserror",
3826+]
3827+
2776 [[package]]3828 [[package]]
2777 name = "turso"3829 name = "turso"
2778 version = "0.8.3"3830 version = "0.8.3"
@@ -3084,6 +4136,12 @@ version = "1.0.4"
3084 source = "registry+https://github.com/rust-lang/crates.io-index"4136 source = "registry+https://github.com/rust-lang/crates.io-index"
3085 checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"4137 checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
3086 4138
4139+[[package]]
4140+name = "utf8parse"
4141+version = "0.2.2"
4142+source = "registry+https://github.com/rust-lang/crates.io-index"
4143+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
4144+
3087 [[package]]4145 [[package]]
3088 name = "uuid"4146 name = "uuid"
3089 version = "1.29.0"4147 version = "1.29.0"
@@ -3359,6 +4417,9 @@ name = "winnow"
3359 version = "1.0.4"4417 version = "1.0.4"
3360 source = "registry+https://github.com/rust-lang/crates.io-index"4418 source = "registry+https://github.com/rust-lang/crates.io-index"
3361 checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"4419 checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
4420+dependencies = [
4421+ "memchr",
4422+]
3362 4423
3363 [[package]]4424 [[package]]
3364 name = "wit-bindgen"4425 name = "wit-bindgen"
Cargo.tomlmodified+6 -0
@@ -15,7 +15,10 @@ argon2 = "0.6.0"
15 base64 = "0.23.1"15 base64 = "0.23.1"
16 chacha20poly1305 = "0.11.0"16 chacha20poly1305 = "0.11.0"
17 ed25519-dalek = { version = "3.0.0", features = ["rand_core"] }17 ed25519-dalek = { version = "3.0.0", features = ["rand_core"] }
18+futures-util = "0.3.34"
19+grass = "0.13.4"
18 hex = "0.4.3"20 hex = "0.4.3"
21+http = "1.5.0"
19 ipnet = "2.12.2"22 ipnet = "2.12.2"
20 rand = "0.10.3"23 rand = "0.10.3"
21 serde = { version = "1.0.229", features = ["derive"] }24 serde = { version = "1.0.229", features = ["derive"] }
@@ -27,9 +30,12 @@ time = { version = "0.3.55", features = ["formatting", "parsing", "macros"] }
27 tokio = { version = "1.54.1", features = ["sync", "rt", "rt-multi-thread", "macros"] }30 tokio = { version = "1.54.1", features = ["sync", "rt", "rt-multi-thread", "macros"] }
28 toml = "1.1.8"31 toml = "1.1.8"
29 tracing = "0.1.44"32 tracing = "0.1.44"
33+tracing-subscriber = "0.3.23"
30 turso = "0.8.3"34 turso = "0.8.3"
31 ulid = "3.0.0"35 ulid = "3.0.0"
32 tempfile = "3.27.0"36 tempfile = "3.27.0"
37+# web framework
38+topcoat = { version = "0.11.0", default-features = false, features = ["router", "view", "runtime", "cookie", "asset", "serve", "sse", "discover", "multipart"] }
33 # internal crates39 # internal crates
34 im-core = { path = "crates/im-core" }40 im-core = { path = "crates/im-core" }
35 41
crates/im-core/src/store/mod.rsmodified+10 -0
@@ -91,6 +91,16 @@ impl Store {
91 self.inner.readers[start].lock().await91 self.inner.readers[start].lock().await
92 }92 }
93 93
94+ /// Runs `SELECT 1` on a pooled reader and fails when the database does not answer. The health
95+ /// route calls it with a deadline, so a stuck lock shows up as a failed probe.
96+ pub async fn ping(&self) -> Result<()> {
97+ let conn = self.read_conn().await;
98+ fetch_opt(&conn, "SELECT 1", (), |row| col_int(row, 0))
99+ .await?
100+ .ok_or_else(missing_row)
101+ .map(|_| ())
102+ }
103+
94 /// Number of user rows. Used to decide whether first-run setup is still open.104 /// Number of user rows. Used to decide whether first-run setup is still open.
95 pub async fn user_count(&self) -> Result<u64> {105 pub async fn user_count(&self) -> Result<u64> {
96 let conn = self.read_conn().await;106 let conn = self.read_conn().await;
crates/im-web/Cargo.tomlmodified+22 -3
@@ -5,9 +5,28 @@ edition.workspace = true
5 license.workspace = true5 license.workspace = true
6 publish = false6 publish = false
7 7
8-[lints]
9-workspace = true
10-
11 [[bin]]8 [[bin]]
12 name = "im"9 name = "im"
13 path = "src/main.rs"10 path = "src/main.rs"
11+
12+[dependencies]
13+futures-util.workspace = true
14+http.workspace = true
15+im-core.workspace = true
16+serde.workspace = true
17+# `net` and `signal` for the listener and the shutdown signals, `time` for the database probe timeout.
18+tokio = { workspace = true, features = ["net", "signal", "time"] }
19+topcoat.workspace = true
20+tracing.workspace = true
21+tracing-subscriber = { workspace = true, features = ["env-filter"] }
22+
23+[dev-dependencies]
24+tempfile.workspace = true
25+
26+[build-dependencies]
27+grass.workspace = true
28+hex.workspace = true
29+sha2.workspace = true
30+
31+[lints]
32+workspace = true
crates/im-web/assets/nav.jsadded+528 -0
@@ -0,0 +1,528 @@
1+/*
2+ * nav.js: the one script of im. Everything in it is progressive enhancement. A page works without
3+ * it as plain HTML; this file only makes the same pages feel like one application.
4+ *
5+ * What it does:
6+ * - Soft navigation. A click on a same-origin link, or a submit of a same-origin form, is fetched
7+ * with fetch(). The <main> element and the <title> of the answer replace the current ones, and
8+ * the URL goes into the history. Back and forward fetch the page again and restore the scroll.
9+ * - Live refresh. Each distinct data-live URL on the page gets one EventSource. A `changed` event
10+ * re-fetches the current page after a short debounce. A refresh keeps the scroll position, the
11+ * focused control and the fields the user edited, so a page that changes under the user does not
12+ * lose their typing.
13+ * - Server restarting. /-/alive is held open on every page. While it is down, or while a form POST
14+ * got no answer, a bar says so. The bar text comes from data-restart-text on <body>, so the
15+ * server translates it.
16+ * - Offline pages. Registers /assets/sw.js, which answers failed page loads with the offline page.
17+ *
18+ * What it never does: send a POST twice. A POST that got no answer is not repeated. Its form stays
19+ * as the user left it, and the bar says the server could not be reached.
20+ *
21+ * The file is one IIFE with no globals. It is loaded with `defer`, so <main> and the data-live
22+ * attributes exist when it runs.
23+ */
24+(function () {
25+ "use strict";
26+
27+ // Without these the page is plain HTML, which is the behaviour we want anyway.
28+ if (!window.fetch || !window.DOMParser || !window.EventSource || !window.history) {
29+ return;
30+ }
31+
32+ /** The server-held stream that tells the page the server is up. */
33+ const ALIVE_PATH = "/-/alive";
34+
35+ /** Paths that always do a full page load. Assets are static; the API is not for pages. */
36+ const HARD_PREFIXES = ["/assets/", "/api/"];
37+
38+ /** Milliseconds between a `changed` event and the refresh it causes. Coalesces a burst of events. */
39+ const REFRESH_DEBOUNCE_MS = 250;
40+
41+ /** Reconnect delays for a stream the browser gave up on. The last value repeats. */
42+ const RECONNECT_MS = [1000, 2000, 3000];
43+
44+ /** Asks for HTML, so the server answers with a page and not with JSON. */
45+ const ACCEPT = "text/html, application/xhtml+xml";
46+
47+ /** Input types whose value must never be kept or replayed by this script. */
48+ const SKIPPED_TYPES = ["password", "file", "hidden", "submit", "button", "reset", "image"];
49+
50+ /** Newest navigation (link, form, history move). An older answer that arrives later is dropped. */
51+ let navSeq = 0;
52+
53+ /** Page-changing requests in flight. A live refresh waits until there are none. */
54+ let busy = 0;
55+
56+ /** The URL the page currently shows, without caring about its hash. */
57+ let currentHref = location.href;
58+
59+ /** Set while /-/alive is unreachable. */
60+ let serverDown = false;
61+
62+ /** Set when a form POST got no answer. Cleared by the next answer. */
63+ let postUnanswered = false;
64+
65+ /** The timer of the pending live refresh. */
66+ let refreshTimer = 0;
67+
68+ /** The restart bar, created the first time it is needed. */
69+ let restartBar = null;
70+
71+ /** Open live streams, by absolute URL. Each value is what hold() returned. */
72+ const streams = new Map();
73+
74+ // ---------------------------------------------------------------------------------------------
75+ // Which links and forms are ours to handle.
76+
77+ /** Parses `href` against the current page. Null when it is not a URL. */
78+ function parseUrl(href) {
79+ try {
80+ return new URL(href, location.href);
81+ } catch (error) {
82+ return null;
83+ }
84+ }
85+
86+ /** True when `url` may be fetched and swapped in: same origin, and not an asset or API path. */
87+ function isSoftTarget(url) {
88+ if (!url || url.origin !== location.origin) {
89+ return false;
90+ }
91+ return !HARD_PREFIXES.some((prefix) => url.pathname.startsWith(prefix));
92+ }
93+
94+ /** The URL without its fragment. A change of only the fragment is a same-page jump, not a load. */
95+ function withoutHash(href) {
96+ return href.split("#")[0];
97+ }
98+
99+ // ---------------------------------------------------------------------------------------------
100+ // The restart bar.
101+
102+ /** Shows or hides the bar, as the union of "server down" and "a POST got no answer". */
103+ function updateRestartBar() {
104+ const show = serverDown || postUnanswered;
105+ if (show && !restartBar) {
106+ restartBar = document.createElement("div");
107+ restartBar.className = "restart-bar";
108+ restartBar.setAttribute("role", "status");
109+ restartBar.textContent = document.body.dataset.restartText || "";
110+ document.body.appendChild(restartBar);
111+ }
112+ if (restartBar) {
113+ restartBar.hidden = !show;
114+ }
115+ }
116+
117+ /** Counts page-changing requests so the page can dim while one is running. */
118+ function addBusy(delta) {
119+ busy += delta;
120+ document.body.classList.toggle("is-loading", busy > 0);
121+ }
122+
123+ // ---------------------------------------------------------------------------------------------
124+ // Streams: one EventSource per URL, kept open with reconnects.
125+
126+ /**
127+ * Opens an EventSource to `url` and keeps it open. The browser reconnects by itself while it
128+ * still tries; once it gives up (readyState CLOSED), this reopens the stream after 1, 2 and then
129+ * 3 seconds. `hooks.events` maps event names to handlers, `hooks.lost` runs when the connection
130+ * drops, and `hooks.back` runs when it opens again after a drop. Returns a handle with close().
131+ */
132+ function hold(url, hooks) {
133+ const link = { source: null, failures: 0, timer: 0, lost: false, closed: false };
134+
135+ const connect = () => {
136+ const source = new EventSource(url);
137+ link.source = source;
138+ source.addEventListener("open", () => {
139+ link.failures = 0;
140+ if (link.lost) {
141+ link.lost = false;
142+ if (hooks.back) hooks.back();
143+ }
144+ });
145+ for (const [name, handler] of Object.entries(hooks.events || {})) {
146+ source.addEventListener(name, handler);
147+ }
148+ source.addEventListener("error", () => {
149+ if (link.closed) return;
150+ if (!link.lost) {
151+ link.lost = true;
152+ if (hooks.lost) hooks.lost();
153+ }
154+ if (source.readyState !== EventSource.CLOSED) return;
155+ source.close();
156+ const delay = RECONNECT_MS[Math.min(link.failures, RECONNECT_MS.length - 1)];
157+ link.failures += 1;
158+ link.timer = setTimeout(connect, delay);
159+ });
160+ };
161+
162+ connect();
163+ return {
164+ close() {
165+ link.closed = true;
166+ clearTimeout(link.timer);
167+ if (link.source) link.source.close();
168+ },
169+ };
170+ }
171+
172+ /** Holds /-/alive. It only drives the restart bar; the server sends nothing else on it yet. */
173+ function holdAlive() {
174+ hold(ALIVE_PATH, {
175+ lost: () => {
176+ serverDown = true;
177+ updateRestartBar();
178+ },
179+ back: () => {
180+ serverDown = false;
181+ updateRestartBar();
182+ },
183+ });
184+ }
185+
186+ /**
187+ * Makes the open streams match the data-live URLs of the page: one stream per distinct URL, and
188+ * a stream whose URL is no longer on the page is closed.
189+ */
190+ function syncStreams() {
191+ const wanted = new Set();
192+ for (const el of document.querySelectorAll("[data-live]")) {
193+ const url = parseUrl(el.getAttribute("data-live"));
194+ if (isSoftTarget(url)) {
195+ wanted.add(url.href);
196+ }
197+ }
198+ for (const [href, handle] of streams) {
199+ if (!wanted.has(href)) {
200+ handle.close();
201+ streams.delete(href);
202+ }
203+ }
204+ for (const href of wanted) {
205+ if (!streams.has(href)) {
206+ streams.set(
207+ href,
208+ hold(href, {
209+ events: { changed: () => scheduleRefresh() },
210+ // Changes made while the stream was down are caught up by one refresh.
211+ back: () => scheduleRefresh(),
212+ })
213+ );
214+ }
215+ }
216+ }
217+
218+ /** Re-fetches the current page soon. Several `changed` events in a row make one refresh. */
219+ function scheduleRefresh() {
220+ clearTimeout(refreshTimer);
221+ refreshTimer = setTimeout(() => {
222+ refreshTimer = 0;
223+ navigate(location.href, "refresh", 0);
224+ }, REFRESH_DEBOUNCE_MS);
225+ }
226+
227+ // ---------------------------------------------------------------------------------------------
228+ // Form fields and focus, kept across a live refresh.
229+
230+ /** The named controls of `root` whose value the script may keep. */
231+ function keepableControls(root) {
232+ return Array.from(root.querySelectorAll("input, textarea, select")).filter(
233+ (el) => el.name && !SKIPPED_TYPES.includes(el.type)
234+ );
235+ }
236+
237+ /** True when the user changed the control, so its server value is not the one shown. */
238+ function isDirty(el) {
239+ if (el.type === "checkbox" || el.type === "radio") {
240+ return el.checked !== el.defaultChecked;
241+ }
242+ if (el.tagName === "SELECT") {
243+ return Array.from(el.options).some((o) => o.selected !== o.defaultSelected);
244+ }
245+ return el.value !== el.defaultValue;
246+ }
247+
248+ /**
249+ * A key that finds the same control in a re-rendered <main>: its id, or its name plus its index
250+ * among the controls with that name. Null for an element with neither.
251+ */
252+ function keyOf(el, root) {
253+ if (el.id) return JSON.stringify(["id", el.id]);
254+ if (!el.name) return null;
255+ const same = Array.from(root.querySelectorAll("[name]")).filter((n) => n.name === el.name);
256+ return JSON.stringify(["name", el.name, same.indexOf(el)]);
257+ }
258+
259+ /** The element that `key` names in `root`, or null. */
260+ function findByKey(key, root) {
261+ if (!key) return null;
262+ const [kind, value, index] = JSON.parse(key);
263+ if (kind === "id") {
264+ return Array.from(root.querySelectorAll("[id]")).find((n) => n.id === value) || null;
265+ }
266+ const same = Array.from(root.querySelectorAll("[name]")).filter((n) => n.name === value);
267+ return same[index] || null;
268+ }
269+
270+ /** What a refresh must put back: the scroll, the focused control and the fields the user changed. */
271+ function captureState() {
272+ const main = document.querySelector("main");
273+ const active = document.activeElement;
274+ const dirty = main
275+ ? keepableControls(main)
276+ .filter(isDirty)
277+ .map((el) => ({
278+ key: keyOf(el, main),
279+ checked: el.checked,
280+ value: el.value,
281+ }))
282+ : [];
283+ return {
284+ y: window.scrollY,
285+ focus: main && active && main.contains(active) ? keyOf(active, main) : null,
286+ fields: dirty,
287+ };
288+ }
289+
290+ /** Puts back what captureState() saw. Fields the server no longer renders are skipped. */
291+ function restoreState(state) {
292+ const main = document.querySelector("main");
293+ if (!main || !state) return;
294+ for (const saved of state.fields) {
295+ const el = findByKey(saved.key, main);
296+ if (!el || !keepableControls(main).includes(el)) continue;
297+ if (el.type === "checkbox" || el.type === "radio") {
298+ el.checked = saved.checked;
299+ } else {
300+ el.value = saved.value;
301+ }
302+ }
303+ const focused = findByKey(state.focus, main);
304+ if (focused) focused.focus({ preventScroll: true });
305+ window.scrollTo(0, state.y);
306+ }
307+
308+ // ---------------------------------------------------------------------------------------------
309+ // Swapping the page in.
310+
311+ /**
312+ * Replaces <main> and the title with the ones of `doc`, and syncs the live streams. Returns false
313+ * when `doc` has no <main>, so the caller can fall back to a full load.
314+ */
315+ function swapIn(doc) {
316+ const fresh = doc.querySelector("main");
317+ const old = document.querySelector("main");
318+ if (!fresh || !old) return false;
319+ document.title = doc.title;
320+ const lang = doc.documentElement.getAttribute("lang");
321+ if (lang) document.documentElement.setAttribute("lang", lang);
322+ old.replaceWith(document.adoptNode(fresh));
323+ syncStreams();
324+ return true;
325+ }
326+
327+ /** Remembers the scroll position of the page being left, so Back can return to it. */
328+ function saveScroll() {
329+ history.replaceState(Object.assign({}, history.state, { y: window.scrollY }), "");
330+ }
331+
332+ /**
333+ * Fetches `href` with a GET. Resolves to the response and its text, or to null when the request
334+ * failed before any answer. Non-HTML answers come back with `text` set to null.
335+ */
336+ async function getPage(href) {
337+ try {
338+ const res = await fetch(href, { headers: { Accept: ACCEPT }, credentials: "same-origin" });
339+ const isHtml = (res.headers.get("content-type") || "").includes("text/html");
340+ return { res, text: isHtml ? await res.text() : null };
341+ } catch (error) {
342+ // The connection failed, or the body was cut off. Either way there is no page to show.
343+ return null;
344+ }
345+ }
346+
347+ /**
348+ * Shows a fetched page. `mode` is "push" (a new history entry), "pop" (Back or Forward) or
349+ * "refresh" (a live refresh in place). `finalHref` is the URL after redirects.
350+ */
351+ function show(text, finalHref, mode, state) {
352+ const doc = new DOMParser().parseFromString(text, "text/html");
353+ if (!swapIn(doc)) {
354+ location.assign(finalHref);
355+ return;
356+ }
357+ currentHref = finalHref;
358+ const main = document.querySelector("main");
359+ if (mode === "refresh") {
360+ restoreState(state);
361+ return;
362+ }
363+ if (mode === "push") {
364+ history.pushState({ y: 0 }, "", finalHref);
365+ const hash = new URL(finalHref).hash.slice(1);
366+ const target = hash ? document.getElementById(hash) : null;
367+ if (target) {
368+ target.scrollIntoView();
369+ } else {
370+ window.scrollTo(0, 0);
371+ }
372+ }
373+ if (mode === "pop") {
374+ window.scrollTo(0, state);
375+ }
376+ if (main) {
377+ main.setAttribute("tabindex", "-1");
378+ main.focus({ preventScroll: true });
379+ }
380+ }
381+
382+ // ---------------------------------------------------------------------------------------------
383+ // Navigation: links, GET forms, POST forms, Back and Forward, and live refresh.
384+
385+ /**
386+ * Loads `href` into the page. `mode` is "push", "pop" or "refresh" (see show()). `y` is the scroll
387+ * to restore on "pop". A failed GET for a link or a history move falls back to a full load, which
388+ * shows the browser's own error. A failed refresh does nothing: the bar covers a dead server.
389+ */
390+ async function navigate(href, mode, y) {
391+ const refresh = mode === "refresh";
392+ if (refresh && busy > 0) return;
393+ const seq = refresh ? navSeq : ++navSeq;
394+ const state = refresh ? captureState() : y;
395+ if (mode === "push") saveScroll();
396+
397+ addBusy(1);
398+ const answer = await getPage(href);
399+ addBusy(-1);
400+
401+ // A newer navigation started, or a refresh was superseded: this answer is out of date.
402+ if (seq !== navSeq) return;
403+ if (!answer) {
404+ if (!refresh) location.assign(href);
405+ return;
406+ }
407+ postUnanswered = false;
408+ updateRestartBar();
409+ if (answer.text === null) {
410+ // A download or another non-page answer: let the browser handle that URL.
411+ if (!refresh) location.assign(answer.res.url || href);
412+ return;
413+ }
414+ show(answer.text, answer.res.url || href, mode, state);
415+ }
416+
417+ /**
418+ * Sends a form. A GET form becomes a navigation to the URL with the form's fields. A POST is sent
419+ * once with fetch(); when it gets no answer the form is kept and the bar is shown. It is never
420+ * sent again by this script.
421+ */
422+ async function submitForm(form, submitter, action, method) {
423+ const data = new FormData(form, submitter || undefined);
424+ if (method === "get") {
425+ const url = new URL(action.href);
426+ url.search = new URLSearchParams(data).toString();
427+ navigate(url.href, "push", 0);
428+ return;
429+ }
430+
431+ // A form that is already sending is not sent twice by a second submit.
432+ form.dataset.sending = "1";
433+ const enctype = (submitter && submitter.getAttribute("formenctype")) || form.enctype || "";
434+ const body = enctype.startsWith("multipart/") ? data : new URLSearchParams(data);
435+
436+ const seq = ++navSeq;
437+ addBusy(1);
438+ let res = null;
439+ let text = null;
440+ try {
441+ res = await fetch(action.href, {
442+ method: "POST",
443+ body,
444+ headers: { Accept: ACCEPT },
445+ credentials: "same-origin",
446+ redirect: "follow",
447+ });
448+ if ((res.headers.get("content-type") || "").includes("text/html")) {
449+ text = await res.text();
450+ }
451+ } catch (error) {
452+ // No answer. The request may or may not have reached the server, so it is not repeated.
453+ res = null;
454+ }
455+ addBusy(-1);
456+ delete form.dataset.sending;
457+
458+ if (seq !== navSeq) return;
459+ if (!res) {
460+ postUnanswered = true;
461+ updateRestartBar();
462+ return;
463+ }
464+ postUnanswered = false;
465+ updateRestartBar();
466+ if (text === null) {
467+ // The POST was answered with a download or another non-page. Show its final URL with a GET.
468+ location.assign(res.url || action.href);
469+ return;
470+ }
471+ show(text, res.url || action.href, "push", 0);
472+ }
473+
474+ // Links. A click on a link we handle is taken over; anything else is left to the browser.
475+ document.addEventListener("click", (event) => {
476+ if (event.defaultPrevented || event.button !== 0) return;
477+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
478+ const link = event.target instanceof Element ? event.target.closest("a[href]") : null;
479+ if (!link || link.hasAttribute("data-hard") || link.hasAttribute("download")) return;
480+ if (link.target && link.target !== "_self") return;
481+ const raw = link.getAttribute("href");
482+ if (raw.startsWith("//")) return;
483+ const url = parseUrl(raw);
484+ if (!isSoftTarget(url)) return;
485+ // A link to a fragment of this page is an ordinary scroll.
486+ if (withoutHash(url.href) === withoutHash(location.href) && url.hash) return;
487+ event.preventDefault();
488+ navigate(url.href, "push", 0);
489+ });
490+
491+ // Forms. A submit we handle is taken over; the browser does not send it.
492+ document.addEventListener("submit", (event) => {
493+ const form = event.target;
494+ if (!(form instanceof HTMLFormElement) || event.defaultPrevented) return;
495+ if (form.hasAttribute("data-hard") || (form.target && form.target !== "_self")) return;
496+ const method = (form.getAttribute("method") || "get").toLowerCase();
497+ if (method !== "get" && method !== "post") return;
498+ const action = parseUrl(form.getAttribute("action") || location.href);
499+ if (!isSoftTarget(action)) return;
500+ if (form.dataset.sending) {
501+ event.preventDefault();
502+ return;
503+ }
504+ event.preventDefault();
505+ submitForm(form, event.submitter, action, method);
506+ });
507+
508+ // Back and Forward. A jump inside the page only moves the scroll; anything else is fetched.
509+ window.addEventListener("popstate", (event) => {
510+ if (withoutHash(location.href) === withoutHash(currentHref)) {
511+ currentHref = location.href;
512+ return;
513+ }
514+ const y = event.state && typeof event.state.y === "number" ? event.state.y : 0;
515+ navigate(location.href, "pop", y);
516+ });
517+
518+ // ---------------------------------------------------------------------------------------------
519+ // Start.
520+
521+ holdAlive();
522+ syncStreams();
523+
524+ // The worker only answers failed page loads. It is registered at the root so it can.
525+ if ("serviceWorker" in navigator) {
526+ navigator.serviceWorker.register("/assets/sw.js", { scope: "/" }).catch(() => {});
527+ }
528+})();
crates/im-web/assets/offline.htmladded+20 -0
@@ -0,0 +1,20 @@
1+<!DOCTYPE html>
2+<html lang="en">
3+<head>
4+<meta charset="utf-8">
5+<meta name="viewport" content="width=device-width, initial-scale=1">
6+<meta name="robots" content="noindex">
7+<meta http-equiv="refresh" content="5">
8+<title>im · offline</title>
9+<link rel="stylesheet" href="/assets/main.css">
10+</head>
11+<body>
12+<main class="page">
13+<section class="empty-state">
14+<h1>im is offline</h1>
15+<p>The server is not answering. This page checks again every 5 seconds.</p>
16+<p lang="tr">Sunucu yanıt vermiyor. Bu sayfa her 5 saniyede bir yeniden dener.</p>
17+</section>
18+</main>
19+</body>
20+</html>
crates/im-web/assets/pages.jsadded+9 -0
@@ -0,0 +1,9 @@
1+/*
2+ * pages.js: small behaviours of individual pages (a dropdown search, a copy button and so on). It
3+ * is empty for now. The file exists so the shell can load it and its content hash is already in the
4+ * page links. Each behaviour, when it is added, does nothing unless its own data attribute is on the
5+ * page. Like nav.js, it is one IIFE with no globals.
6+ */
7+(function () {
8+ "use strict";
9+})();
crates/im-web/assets/sw.jsadded+46 -0
@@ -0,0 +1,46 @@
1+/*
2+ * sw.js: the service worker of im. It does one thing. When a page load fails because the server
3+ * cannot be reached, it answers with /assets/offline.html, which checks again every few seconds.
4+ * Everything else goes to the network untouched, so a page never shows data that is out of date.
5+ */
6+
7+/** The cache that holds the offline page. Bump the number when offline.html changes. */
8+const CACHE = "im-offline-1";
9+
10+/** The page answered when a navigation fails. */
11+const OFFLINE_PAGE = "/assets/offline.html";
12+
13+self.addEventListener("install", (event) => {
14+ event.waitUntil(
15+ caches
16+ .open(CACHE)
17+ .then((cache) => cache.add(OFFLINE_PAGE))
18+ .then(() => self.skipWaiting())
19+ );
20+});
21+
22+self.addEventListener("activate", (event) => {
23+ // Drop the caches of earlier versions, then take control of the open pages.
24+ event.waitUntil(
25+ caches
26+ .keys()
27+ .then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
28+ .then(() => self.clients.claim())
29+ );
30+});
31+
32+self.addEventListener("fetch", (event) => {
33+ const request = event.request;
34+ // Only a GET navigation is answered. Retrying a POST here would send the form a second time.
35+ if (request.mode !== "navigate" || request.method !== "GET") {
36+ return;
37+ }
38+ event.respondWith(
39+ fetch(request).catch(() =>
40+ caches
41+ .open(CACHE)
42+ .then((cache) => cache.match(OFFLINE_PAGE))
43+ .then((page) => page || Response.error())
44+ )
45+ );
46+});
crates/im-web/build.rsadded+57 -0
@@ -0,0 +1,57 @@
1+//! Build script of the `im` binary. It compiles `style/main.scss` into `OUT_DIR/main.css`, and it
2+//! emits the build identity and the content hashes that the page links use as cache-busting
3+//! queries: `IM_MAIN_CSS_V`, `IM_NAV_JS_V`, `IM_PAGES_JS_V` and `IM_BUILD_SHA`.
4+//!
5+//! It does not decide what is served: `src/assets.rs` embeds the files. It does not decide what a
6+//! page links to either: `src/assets.rs` builds the `?v=` URLs from these values. It only compiles
7+//! and hashes, so a changed file gets a new hash and an unchanged file keeps its URL.
8+
9+use std::{env, fs, path::PathBuf};
10+
11+use hex::encode;
12+use sha2::{Digest, Sha256};
13+
14+/// Number of hex characters of the SHA-256 that make a content version. Twelve characters are 48
15+/// bits, which is plenty to tell two builds of one file apart.
16+const VERSION_HEX_LEN: usize = 12;
17+
18+fn main() {
19+ println!("cargo:rerun-if-env-changed=IM_BUILD_SHA");
20+ println!("cargo:rerun-if-changed=../../style");
21+ println!("cargo:rerun-if-changed=assets");
22+ println!("cargo:rerun-if-changed=build.rs");
23+
24+ // The commit identity shown by `/healthz`. The release script sets it; a local build says `dev`.
25+ let sha = env::var("IM_BUILD_SHA").unwrap_or_else(|_| "dev".to_owned());
26+ println!("cargo:rustc-env=IM_BUILD_SHA={sha}");
27+
28+ let manifest =
29+ PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("cargo sets the manifest dir"));
30+ let out = PathBuf::from(env::var("OUT_DIR").expect("cargo sets OUT_DIR"));
31+
32+ // The stylesheet is compiled from the repository-level `style/` directory. Its partials are
33+ // `@use`d relative to `main.scss`, so no load path is needed.
34+ let css = grass::from_path(
35+ manifest.join("../../style/main.scss"),
36+ &grass::Options::default(),
37+ )
38+ .unwrap_or_else(|e| panic!("compiling style/main.scss: {e}"));
39+ fs::write(out.join("main.css"), &css).expect("writing the compiled stylesheet to OUT_DIR");
40+ println!(
41+ "cargo:rustc-env=IM_MAIN_CSS_V={}",
42+ content_version(css.as_bytes())
43+ );
44+
45+ for (var, file) in [
46+ ("IM_NAV_JS_V", "assets/nav.js"),
47+ ("IM_PAGES_JS_V", "assets/pages.js"),
48+ ] {
49+ let bytes = fs::read(manifest.join(file)).unwrap_or_else(|e| panic!("reading {file}: {e}"));
50+ println!("cargo:rustc-env={var}={}", content_version(&bytes));
51+ }
52+}
53+
54+/// The first `VERSION_HEX_LEN` hex characters of the SHA-256 of `bytes`.
55+fn content_version(bytes: &[u8]) -> String {
56+ encode(Sha256::digest(bytes))[..VERSION_HEX_LEN].to_owned()
57+}
crates/im-web/src/assets.rsadded+75 -0
@@ -0,0 +1,75 @@
1+//! The static files of the UI, compiled into the binary and served from `/assets/`.
2+//!
3+//! The CSS is compiled from `style/` by `build.rs`. The scripts and the offline page are in
4+//! `crates/im-web/assets/`. Each link to a file that changes with a build carries the first 12
5+//! hex digits of its SHA-256 as `?v=`, so a changed file gets a new URL and an unchanged one keeps
6+//! its cache entry. Files whose URL does not change (the service worker and the offline page) are
7+//! served with `no-cache`.
8+
9+use topcoat::Result;
10+use topcoat::router::{HeaderMap, HeaderValue, StatusCode, header, route};
11+
12+/// Link to the stylesheet, with its content version.
13+pub const MAIN_CSS_HREF: &str = concat!("/assets/main.css?v=", env!("IM_MAIN_CSS_V"));
14+
15+/// Link to the script that makes navigation soft and drives the live pages.
16+pub const NAV_JS_HREF: &str = concat!("/assets/nav.js?v=", env!("IM_NAV_JS_V"));
17+
18+/// Link to the script of individual pages.
19+pub const PAGES_JS_HREF: &str = concat!("/assets/pages.js?v=", env!("IM_PAGES_JS_V"));
20+
21+const MAIN_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css"));
22+const NAV_JS: &str = include_str!("../assets/nav.js");
23+const PAGES_JS: &str = include_str!("../assets/pages.js");
24+const OFFLINE_HTML: &str = include_str!("../assets/offline.html");
25+const SW_JS: &str = include_str!("../assets/sw.js");
26+
27+/// A content-versioned file. The URL changes with the bytes, so the browser may keep it for a year.
28+const IMMUTABLE: &str = "public, max-age=31536000, immutable";
29+
30+/// A file whose URL stays the same across builds. The browser must ask again each time.
31+const REVALIDATE: &str = "no-cache";
32+
33+/// The status, headers and body of an asset answer.
34+type Asset = (StatusCode, HeaderMap, &'static str);
35+
36+/// Builds the answer for one asset: the content type and the cache policy.
37+fn asset(content_type: &'static str, cache: &'static str, body: &'static str) -> Asset {
38+ let mut headers = HeaderMap::new();
39+ headers.insert(header::CONTENT_TYPE, HeaderValue::from_static(content_type));
40+ headers.insert(header::CACHE_CONTROL, HeaderValue::from_static(cache));
41+ (StatusCode::OK, headers, body)
42+}
43+
44+/// `GET /assets/main.css`.
45+#[route(GET "/assets/main.css")]
46+async fn main_css() -> Result<Asset> {
47+ Ok(asset("text/css; charset=utf-8", IMMUTABLE, MAIN_CSS))
48+}
49+
50+/// `GET /assets/nav.js`.
51+#[route(GET "/assets/nav.js")]
52+async fn nav_js() -> Result<Asset> {
53+ Ok(asset("text/javascript; charset=utf-8", IMMUTABLE, NAV_JS))
54+}
55+
56+/// `GET /assets/pages.js`.
57+#[route(GET "/assets/pages.js")]
58+async fn pages_js() -> Result<Asset> {
59+ Ok(asset("text/javascript; charset=utf-8", IMMUTABLE, PAGES_JS))
60+}
61+
62+/// `GET /assets/offline.html`. Also precached by the service worker.
63+#[route(GET "/assets/offline.html")]
64+async fn offline_html() -> Result<Asset> {
65+ Ok(asset("text/html; charset=utf-8", REVALIDATE, OFFLINE_HTML))
66+}
67+
68+/// `GET /assets/sw.js`. It is served at the root scope, which needs the `Service-Worker-Allowed`
69+/// header; without it the browser would limit the worker to `/assets/`.
70+#[route(GET "/assets/sw.js")]
71+async fn sw_js() -> Result<Asset> {
72+ let (status, mut headers, body) = asset("text/javascript; charset=utf-8", REVALIDATE, SW_JS);
73+ headers.insert("service-worker-allowed", HeaderValue::from_static("/"));
74+ Ok((status, headers, body))
75+}
crates/im-web/src/boot.rsadded+199 -0
@@ -0,0 +1,199 @@
1+//! Boot: the order in which the server comes up, the router it serves, and the shutdown.
2+//!
3+//! The order follows `docs/conventions.md` section 2: load the configuration, create the data
4+//! directory with mode 0700, load or create the instance key, open the database (which applies
5+//! the pragmas and the migrations), build the router, bind the listener, and serve until SIGTERM or
6+//! Ctrl-C. Stored UI overrides are not layered on the file yet, because no page writes them.
7+
8+use std::os::unix::fs::PermissionsExt;
9+use std::path::Path;
10+use std::sync::Arc;
11+
12+use im_core::config::Config;
13+use im_core::secret;
14+use im_core::store::Store;
15+use tokio::net::TcpListener;
16+use tokio::signal::unix::{SignalKind, signal};
17+use tokio::sync::watch;
18+use topcoat::cookie::RouterBuilderCookieExt;
19+use topcoat::router::{Router, RouterBuilderDiscoverExt, RouterService};
20+
21+use crate::live::LiveHub;
22+use crate::pages::not_found::NotFoundLayer;
23+use crate::security::{self, SecurityHeaders};
24+use crate::state::AppState;
25+
26+/// Name of the instance key file inside the data directory.
27+const KEY_FILE: &str = "im.key";
28+
29+/// Runs the server until a stop signal arrives. Returns once every connection has finished.
30+pub async fn serve(config_path: &Path) -> im_core::Result<()> {
31+ let config = Config::load(config_path)?;
32+ let listen = config.listen;
33+ let state = open_state(config).await?;
34+
35+ let listener = TcpListener::bind(listen).await.map_err(|error| {
36+ std::io::Error::new(error.kind(), format!("cannot bind {listen}: {error}"))
37+ })?;
38+ tracing::info!(
39+ listen = %listen,
40+ data_dir = %state.config.data_dir.display(),
41+ build = env!("IM_BUILD_SHA"),
42+ "im starting"
43+ );
44+
45+ // One stop flag. The signal task sets it; the server watches it and then drains.
46+ let (stop_tx, stop_rx) = watch::channel(false);
47+ tokio::spawn(async move {
48+ shutdown_signal().await;
49+ tracing::info!("shutdown signal received");
50+ stop_tx.send_replace(true);
51+ });
52+
53+ topcoat::serve_until(
54+ listener,
55+ RouterService::new(router(state)),
56+ wait_stop(stop_rx),
57+ )
58+ .await?;
59+ tracing::info!("im stopped");
60+ Ok(())
61+}
62+
63+/// Creates the data directory and opens the key and the database. Everything the router needs
64+/// that touches the disk is ready when this returns.
65+async fn open_state(config: Config) -> im_core::Result<AppState> {
66+ std::fs::create_dir_all(&config.data_dir)?;
67+ // The directory holds the instance key. Only this user may enter it.
68+ std::fs::set_permissions(&config.data_dir, std::fs::Permissions::from_mode(0o700))?;
69+ let data_dir = config.data_dir.canonicalize()?;
70+ if let Some(parent) = config
71+ .database
72+ .parent()
73+ .filter(|p| !p.as_os_str().is_empty())
74+ {
75+ std::fs::create_dir_all(parent)?;
76+ }
77+ let key = secret::load_or_create_key(&data_dir.join(KEY_FILE))?;
78+ let store = Store::open(&config.database).await?;
79+ Ok(AppState {
80+ config: Arc::new(config),
81+ store,
82+ key: Arc::new(key),
83+ live: Arc::new(LiveHub::default()),
84+ })
85+}
86+
87+/// The router of the server: every route and page found by `discover`, the cookie jar, the security
88+/// headers on every response, and the styled 404 for browsers.
89+pub fn router(state: AppState) -> Router {
90+ let security = SecurityHeaders::new(security::headers_for(&state.config.base_url));
91+ Router::builder()
92+ .discover()
93+ .app_context(state)
94+ .cookies()
95+ .layer(security)
96+ .layer(NotFoundLayer)
97+ .build()
98+}
99+
100+/// Resolves when the shared stop flag is set.
101+async fn wait_stop(mut stop: watch::Receiver<bool>) {
102+ let _ = stop.wait_for(|stopped| *stopped).await;
103+}
104+
105+/// Resolves on Ctrl-C or SIGTERM. A handler that cannot be installed is logged and never resolves,
106+/// so the other one still works.
107+async fn shutdown_signal() {
108+ let ctrl_c = async {
109+ if let Err(error) = tokio::signal::ctrl_c().await {
110+ tracing::error!(error = %error, "cannot listen for Ctrl-C");
111+ std::future::pending::<()>().await;
112+ }
113+ };
114+ let terminate = async {
115+ match signal(SignalKind::terminate()) {
116+ Ok(mut term) => {
117+ term.recv().await;
118+ }
119+ Err(error) => {
120+ tracing::error!(error = %error, "cannot listen for SIGTERM");
121+ std::future::pending::<()>().await;
122+ }
123+ }
124+ };
125+ tokio::select! {
126+ () = ctrl_c => {}
127+ () = terminate => {}
128+ }
129+}
130+
131+#[cfg(test)]
132+pub(crate) use tests::test_state;
133+
134+#[cfg(test)]
135+mod tests {
136+ use super::*;
137+ use http::header::{ACCEPT, CONTENT_SECURITY_POLICY, X_CONTENT_TYPE_OPTIONS};
138+ use topcoat::router::response::Response;
139+ use topcoat::router::{Body, to_bytes};
140+
141+ /// An app state over a fresh temp directory: the database and the key live there, and nothing
142+ /// is written outside it. The directory is returned so it lives as long as the state.
143+ pub(crate) async fn test_state() -> (tempfile::TempDir, AppState) {
144+ let dir = tempfile::tempdir().expect("temp dir");
145+ let text = format!(
146+ "database = \"{}\"\ndata_dir = \"{}\"\nlisten = \"127.0.0.1:7650\"\nbase_url = \"http://127.0.0.1:7650\"\n",
147+ dir.path().join("im.db").display(),
148+ dir.path().display(),
149+ );
150+ let config = Config::parse(&text).expect("test config");
151+ let key = secret::load_or_create_key(&dir.path().join(KEY_FILE)).expect("key");
152+ let store = Store::open(&config.database).await.expect("store");
153+ let state = AppState {
154+ config: Arc::new(config),
155+ store,
156+ key: Arc::new(key),
157+ live: Arc::new(LiveHub::default()),
158+ };
159+ (dir, state)
160+ }
161+
162+ async fn get(state: AppState, path: &str, accept: Option<&str>) -> Response {
163+ let mut request = http::Request::get(path);
164+ if let Some(accept) = accept {
165+ request = request.header(ACCEPT, accept);
166+ }
167+ let request = request.body(Body::empty()).expect("request");
168+ router(state).handle(request).await
169+ }
170+
171+ #[tokio::test]
172+ async fn a_page_carries_the_content_security_policy_and_nosniff() {
173+ let (_dir, state) = test_state().await;
174+ let response = get(state, "/", Some("text/html")).await;
175+ assert_eq!(response.status(), 200);
176+ assert_eq!(
177+ response.headers()[CONTENT_SECURITY_POLICY]
178+ .to_str()
179+ .expect("ascii"),
180+ security::CSP
181+ );
182+ assert_eq!(response.headers()[X_CONTENT_TYPE_OPTIONS], "nosniff");
183+ }
184+
185+ #[tokio::test]
186+ async fn an_unknown_path_for_a_browser_gets_the_styled_404() {
187+ let (_dir, state) = test_state().await;
188+ let response = get(state, "/no/such/page", Some("text/html")).await;
189+ assert_eq!(response.status(), 404);
190+ let body = to_bytes(response.into_body(), 64 * 1024)
191+ .await
192+ .expect("body");
193+ let html = String::from_utf8_lossy(&body);
194+ assert!(
195+ html.contains("Page not found"),
196+ "styled 404 body, got: {html}"
197+ );
198+ }
199+}
crates/im-web/src/health.rsadded+63 -0
@@ -0,0 +1,63 @@
1+//! `GET /healthz`, the probe of `docs/contracts.md` section 4.1.
2+//!
3+//! It answers `200` with `ok <build sha>` when the database answers `SELECT 1` within one second,
4+//! and `503` with `fail database` otherwise. It needs no login and reads no user data.
5+
6+use std::time::Duration;
7+
8+use topcoat::Result;
9+use topcoat::context::{Cx, app_context};
10+use topcoat::router::{HeaderMap, HeaderValue, StatusCode, header, route};
11+
12+use crate::state::AppState;
13+
14+/// The longest the database probe may take. A lock held by a long write shows up as a failed probe.
15+const PROBE_DEADLINE: Duration = Duration::from_secs(1);
16+
17+/// `GET /healthz`.
18+#[route(GET "/healthz")]
19+async fn healthz(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> {
20+ let state = app_context::<AppState>(cx);
21+ let (status, body) = match tokio::time::timeout(PROBE_DEADLINE, state.store.ping()).await {
22+ Ok(Ok(())) => (StatusCode::OK, format!("ok {}", env!("IM_BUILD_SHA"))),
23+ Ok(Err(error)) => {
24+ tracing::error!(error = %error, "healthz: the database probe failed");
25+ (StatusCode::SERVICE_UNAVAILABLE, "fail database".to_owned())
26+ }
27+ Err(_) => {
28+ tracing::error!("healthz: the database probe took longer than one second");
29+ (StatusCode::SERVICE_UNAVAILABLE, "fail database".to_owned())
30+ }
31+ };
32+ let mut headers = HeaderMap::new();
33+ headers.insert(
34+ header::CONTENT_TYPE,
35+ HeaderValue::from_static("text/plain; charset=utf-8"),
36+ );
37+ Ok((status, headers, body))
38+}
39+
40+#[cfg(test)]
41+mod tests {
42+ use http::Request;
43+ use topcoat::router::Body;
44+
45+ use crate::boot::{router, test_state};
46+
47+ #[tokio::test]
48+ async fn healthz_answers_ok_with_the_build_sha() {
49+ let (_dir, state) = test_state().await;
50+ let request = Request::get("/healthz")
51+ .body(Body::empty())
52+ .expect("request");
53+ let response = router(state).handle(request).await;
54+ assert_eq!(response.status(), 200);
55+ let body = topcoat::router::to_bytes(response.into_body(), 1024)
56+ .await
57+ .expect("body");
58+ assert_eq!(
59+ body.as_ref(),
60+ format!("ok {}", env!("IM_BUILD_SHA")).as_bytes()
61+ );
62+ }
63+}
crates/im-web/src/i18n/mod.rsadded+116 -0
@@ -0,0 +1,116 @@
1+//! Languages of the UI and how a request picks one. English and Turkish are the only ones.
2+//!
3+//! Every visible string is keyed by an enum in an area module (`shell.rs` for now), and each
4+//! module's `t` function matches on `(key, lang)` exhaustively. A key without a Turkish text
5+//! therefore fails to compile instead of showing English on a Turkish page.
6+//!
7+//! This module decides the language. It does not format sentences with values; those get small
8+//! helper functions next to their keys.
9+
10+pub mod shell;
11+
12+use topcoat::context::Cx;
13+use topcoat::router::request::headers;
14+use topcoat::router::{HeaderMap, header};
15+
16+/// A UI language.
17+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
18+pub enum Lang {
19+ En,
20+ Tr,
21+}
22+
23+impl Lang {
24+ /// Parses a stored language code. Anything other than `en` or `tr` is `None`, which means "no
25+ /// preference" to the caller.
26+ pub fn from_code(code: &str) -> Option<Lang> {
27+ match code {
28+ "en" => Some(Lang::En),
29+ "tr" => Some(Lang::Tr),
30+ _ => None,
31+ }
32+ }
33+
34+ /// The language of a `Accept-Language` tag such as `tr-TR`, by its primary subtag. None for a
35+ /// language this build has no text for.
36+ fn from_tag(tag: &str) -> Option<Lang> {
37+ let primary = tag.split('-').next()?.trim();
38+ Lang::from_code(&primary.to_ascii_lowercase())
39+ }
40+
41+ /// The value of `<html lang>`.
42+ pub fn code(self) -> &'static str {
43+ match self {
44+ Lang::En => "en",
45+ Lang::Tr => "tr",
46+ }
47+ }
48+}
49+
50+/// The language of the current request. See [`resolve`].
51+pub fn lang(cx: &Cx, user_locale: Option<&str>) -> Lang {
52+ resolve(user_locale, headers(cx))
53+}
54+
55+/// The user's stored language when it names one, else the best `Accept-Language` entry this build
56+/// can serve, else English.
57+///
58+/// `user_locale` is the stored value of the account (`en`, `tr`, or nothing for "automatic").
59+pub fn resolve(user_locale: Option<&str>, request_headers: &HeaderMap) -> Lang {
60+ user_locale
61+ .and_then(Lang::from_code)
62+ .or_else(|| accept_language(request_headers))
63+ .unwrap_or(Lang::En)
64+}
65+
66+/// The supported entry with the highest quality. Ties keep the first one listed. Entries with
67+/// `q=0`, an unreadable quality, or a language this build does not have are skipped.
68+fn accept_language(request_headers: &HeaderMap) -> Option<Lang> {
69+ let mut best: Option<(f32, Lang)> = None;
70+ for value in request_headers.get_all(header::ACCEPT_LANGUAGE) {
71+ let Ok(text) = value.to_str() else {
72+ continue;
73+ };
74+ for item in text.split(',') {
75+ let mut parts = item.split(';');
76+ let tag = parts.next().unwrap_or_default().trim();
77+ let quality = parts
78+ .find_map(|part| part.trim().strip_prefix("q="))
79+ .map_or(Some(1.0), |q| q.parse::<f32>().ok());
80+ let Some(quality) = quality.filter(|q| *q > 0.0) else {
81+ continue;
82+ };
83+ let Some(lang) = Lang::from_tag(tag) else {
84+ continue;
85+ };
86+ if best.is_none_or(|(best_quality, _)| quality > best_quality) {
87+ best = Some((quality, lang));
88+ }
89+ }
90+ }
91+ best.map(|(_, lang)| lang)
92+}
93+
94+#[cfg(test)]
95+mod tests {
96+ use super::*;
97+
98+ fn accept(value: &str) -> HeaderMap {
99+ let mut headers = HeaderMap::new();
100+ headers.insert(
101+ header::ACCEPT_LANGUAGE,
102+ value.parse().expect("header value"),
103+ );
104+ headers
105+ }
106+
107+ #[test]
108+ fn the_stored_language_wins_then_accept_language_then_english() {
109+ assert_eq!(resolve(Some("tr"), &accept("en")), Lang::Tr);
110+ assert_eq!(resolve(None, &accept("en;q=0.2, tr;q=0.9")), Lang::Tr);
111+ assert_eq!(resolve(None, &accept("tr-TR,tr;q=0.9,en;q=0.8")), Lang::Tr);
112+ assert_eq!(resolve(None, &accept("fr, de;q=0.5")), Lang::En);
113+ assert_eq!(resolve(Some("auto"), &accept("tr;q=0")), Lang::En);
114+ assert_eq!(resolve(None, &HeaderMap::new()), Lang::En);
115+ }
116+}
crates/im-web/src/i18n/shell.rsadded+55 -0
@@ -0,0 +1,55 @@
1+//! Strings of the shell and of the first pages: the topbar, the restart bar, the 404 page and the
2+//! start page. Area modules hold their own strings as they arrive.
3+
4+use super::Lang;
5+
6+/// One variant per phrase. Add a variant, then its English and Turkish texts in [`t`].
7+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8+pub enum K {
9+ /// The badge shown beside an administrator's name.
10+ Admin,
11+ /// The link on the 404 page that returns to the start page.
12+ BackHome,
13+ /// The title of the start page.
14+ ImIsRunning,
15+ /// The sentence under the 404 title.
16+ NotFoundBody,
17+ /// The title of the 404 page.
18+ NotFoundTitle,
19+ /// The sentence on the start page.
20+ RunningBody,
21+ /// The bar shown while the server cannot be reached.
22+ ServerRestarting,
23+ /// The accessible name of the service switcher.
24+ Services,
25+ /// The first link on every page, which jumps past the topbar.
26+ SkipToContent,
27+}
28+
29+/// The text of `key` in `lang`.
30+pub fn t(lang: Lang, key: K) -> &'static str {
31+ match (key, lang) {
32+ (K::Admin, Lang::En) => "Admin",
33+ (K::Admin, Lang::Tr) => "Yönetici",
34+ (K::BackHome, Lang::En) => "Back to the start",
35+ (K::BackHome, Lang::Tr) => "Başlangıca dön",
36+ (K::ImIsRunning, Lang::En) => "im is running",
37+ (K::ImIsRunning, Lang::Tr) => "im çalışıyor",
38+ (K::NotFoundBody, Lang::En) => "The page does not exist, or you do not have access to it.",
39+ (K::NotFoundBody, Lang::Tr) => "Sayfa yok ya da bu sayfayı görme izniniz yok.",
40+ (K::NotFoundTitle, Lang::En) => "Page not found",
41+ (K::NotFoundTitle, Lang::Tr) => "Sayfa bulunamadı",
42+ (K::RunningBody, Lang::En) => {
43+ "The server answers requests. Sign-in is not part of this build yet."
44+ }
45+ (K::RunningBody, Lang::Tr) => {
46+ "Sunucu istekleri yanıtlıyor. Oturum açma bu sürümde henüz yok."
47+ }
48+ (K::ServerRestarting, Lang::En) => "The server is restarting. Reconnecting…",
49+ (K::ServerRestarting, Lang::Tr) => "Sunucu yeniden başlatılıyor. Yeniden bağlanılıyor…",
50+ (K::Services, Lang::En) => "Services",
51+ (K::Services, Lang::Tr) => "Hizmetler",
52+ (K::SkipToContent, Lang::En) => "Skip to content",
53+ (K::SkipToContent, Lang::Tr) => "İçeriğe geç",
54+ }
55+}
crates/im-web/src/live.rsadded+199 -0
@@ -0,0 +1,199 @@
1+//! Live updates: a change counter per topic, and the server-sent event stream that carries it to
2+//! the browser.
3+//!
4+//! A write that changes what a page shows calls [`LiveHub::bump`] after it commits. A stream that
5+//! subscribed to that topic wakes and sends one `changed` event without data. The browser then
6+//! fetches the page again (`nav.js`), so an event carries no state and a missed one cannot leave the
7+//! page wrong for long. Nothing polls, and a topic nobody listens to is dropped.
8+//!
9+//! The hub is not a queue and not an authorisation check. Each route that opens a stream
10+//! authenticates and authorises first, then calls [`stream_changes`].
11+//!
12+//! Nothing bumps a topic or opens [`stream_changes`] yet, so the items here are kept ahead of the
13+//! pages that use them.
14+
15+#![allow(dead_code)] // The hub and its topics wait for the pages that bump and follow them.
16+
17+use std::collections::HashMap;
18+use std::future::Future;
19+use std::sync::{Mutex, MutexGuard, PoisonError};
20+use std::time::Duration;
21+
22+use futures_util::{Stream, StreamExt, future::select_all, stream};
23+use tokio::sync::watch;
24+use topcoat::Result;
25+use topcoat::context::Cx;
26+use topcoat::router::content::sse::{Event, KeepAlive, Sse};
27+use topcoat::router::response::{IntoResponse, Response};
28+use topcoat::router::{HeaderValue, route};
29+
30+/// How long a client waits before it reconnects when a stream ends. Sent once, at the start.
31+pub const STREAM_RETRY: Duration = Duration::from_millis(1000);
32+
33+/// Silence after which the server sends a keep-alive comment, so proxies keep the stream open.
34+pub const KEEP_ALIVE: Duration = Duration::from_secs(30);
35+
36+/// What a live page follows.
37+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
38+pub enum Topic {
39+ /// A user's own settings, sessions or sign-ins. Keyed by user id. Streamed only to that user.
40+ Account(String),
41+ /// The audit log: an entry was written. Global. Admin pages only.
42+ AdminAudit,
43+}
44+
45+/// The change counters of all open topics. Cheap to share: every clone of the app state holds the
46+/// same `Arc<LiveHub>`.
47+#[derive(Default)]
48+pub struct LiveHub {
49+ topics: Mutex<HashMap<Topic, watch::Sender<u64>>>,
50+}
51+
52+impl LiveHub {
53+ /// Locks the map. A panic in another holder must not stop every live page, so a poisoned lock
54+ /// is used as it is.
55+ fn topics(&self) -> MutexGuard<'_, HashMap<Topic, watch::Sender<u64>>> {
56+ self.topics.lock().unwrap_or_else(PoisonError::into_inner)
57+ }
58+
59+ /// Subscribes to `topic`. The receiver starts as seen, so a bump after this call wakes it.
60+ /// Subscribe before reading the state: a change between the two is then not lost. Topics that
61+ /// nobody holds any more are dropped here, so the map stays small.
62+ pub fn subscribe(&self, topic: &Topic) -> watch::Receiver<u64> {
63+ let mut topics = self.topics();
64+ topics.retain(|_, sender| sender.receiver_count() > 0);
65+ topics
66+ .entry(topic.clone())
67+ .or_insert_with(|| watch::channel(0).0)
68+ .subscribe()
69+ }
70+
71+ /// Wakes the subscribers of `topic`. Does nothing when nobody listens.
72+ pub fn bump(&self, topic: &Topic) {
73+ let mut topics = self.topics();
74+ let Some(sender) = topics.get(topic) else {
75+ return;
76+ };
77+ sender.send_modify(|generation| *generation = generation.wrapping_add(1));
78+ if sender.receiver_count() == 0 {
79+ topics.remove(topic);
80+ }
81+ }
82+}
83+
84+/// The state a stream carries between wakes.
85+struct Follow<F> {
86+ wakes: Vec<watch::Receiver<u64>>,
87+ fingerprint: F,
88+ last: String,
89+}
90+
91+/// Opens the `changed` stream for `topics`. The stream sends an event only when `fingerprint`
92+/// differs from the value it last sent, so a bump that changes nothing the viewer sees sends
93+/// nothing. Nothing is sent on connect: the page already shows the state that `fingerprint` read.
94+///
95+/// `fingerprint` must be cheap and must describe everything the page shows. A read that fails ends
96+/// the stream, and the browser reconnects.
97+pub async fn stream_changes<F, Fut>(
98+ cx: &Cx,
99+ hub: &LiveHub,
100+ topics: &[Topic],
101+ fingerprint: F,
102+) -> Result<Response>
103+where
104+ F: Fn() -> Fut + Send + 'static,
105+ Fut: Future<Output = Result<String>> + Send,
106+{
107+ // Subscribed before the first read, so a change in between still wakes the stream.
108+ let wakes: Vec<watch::Receiver<u64>> =
109+ topics.iter().map(|topic| hub.subscribe(topic)).collect();
110+ let last = fingerprint().await?;
111+ let follow = Follow {
112+ wakes,
113+ fingerprint,
114+ last,
115+ };
116+ let events = stream::unfold(follow, |mut follow| async move {
117+ loop {
118+ if !wait_any(&mut follow.wakes).await {
119+ return None;
120+ }
121+ match (follow.fingerprint)().await {
122+ Ok(now) if now != follow.last => {
123+ follow.last = now;
124+ return Some((changed_event(), follow));
125+ }
126+ Ok(_) => continue,
127+ Err(error) => {
128+ tracing::error!(error = %error, "live: could not read the page state");
129+ return None;
130+ }
131+ }
132+ }
133+ });
134+ events_response(cx, events)
135+}
136+
137+/// The data-less `changed` event.
138+fn changed_event() -> Result<Event> {
139+ Ok(Event::new().event("changed").data("1"))
140+}
141+
142+/// Resolves when one of `wakes` changes. False when that topic is gone, which ends the stream.
143+/// With no topics at all it never resolves: the stream then only sends keep-alives.
144+async fn wait_any(wakes: &mut [watch::Receiver<u64>]) -> bool {
145+ if wakes.is_empty() {
146+ std::future::pending::<()>().await;
147+ }
148+ let waits = wakes.iter_mut().map(|wake| Box::pin(wake.changed()));
149+ let (result, _, _) = select_all(waits).await;
150+ result.is_ok()
151+}
152+
153+/// The response of a live stream: `retry` once, then the events, with keep-alives while idle.
154+/// `X-Accel-Buffering: no` stops a reverse proxy from holding the events back.
155+pub fn events_response(
156+ cx: &Cx,
157+ events: impl Stream<Item = Result<Event>> + Send + 'static,
158+) -> Result<Response> {
159+ let retry = stream::once(std::future::ready(Ok(Event::new().retry(STREAM_RETRY))));
160+ let stream = Sse::new(retry.chain(events))
161+ .keep_alive(KeepAlive::new().interval(KEEP_ALIVE).text("keepalive"));
162+ let mut response = stream.into_response(cx)?;
163+ response
164+ .headers_mut()
165+ .insert("x-accel-buffering", HeaderValue::from_static("no"));
166+ Ok(response)
167+}
168+
169+/// `GET /-/alive`. Every page holds this stream, so the browser learns when the server stops and
170+/// starts again. Anonymous viewers may hold it, and it reveals nothing: for now it sends only the
171+/// `retry` hint and keep-alives.
172+#[route(GET "/-/alive")]
173+async fn alive(cx: &Cx) -> Result<Response> {
174+ events_response(cx, stream::pending::<Result<Event>>())
175+}
176+
177+#[cfg(test)]
178+mod tests {
179+ use std::time::Duration;
180+
181+ use super::*;
182+
183+ #[tokio::test]
184+ async fn a_bump_wakes_only_the_subscribers_of_its_topic() {
185+ let hub = LiveHub::default();
186+ let mine = Topic::Account("user-a".to_owned());
187+ let other = Topic::Account("user-b".to_owned());
188+ let mut wake_mine = hub.subscribe(&mine);
189+ let wake_other = hub.subscribe(&other);
190+
191+ hub.bump(&mine);
192+
193+ tokio::time::timeout(Duration::from_secs(1), wake_mine.changed())
194+ .await
195+ .expect("woken")
196+ .expect("open");
197+ assert!(!wake_other.has_changed().expect("open"));
198+ }
199+}
crates/im-web/src/main.rsmodified+99 -3
@@ -1,5 +1,101 @@
1-//! The `im` binary. Placeholder until the server, CLI and UI land; it only prints its name.1+//! The `im` binary: the command line, logging and the process lifetime.
2+//!
3+//! `im [--config <path>] [serve]` runs the server; a bare `im` does the same. `im admin ...` is the
4+//! operator command line, which is not built yet. The configuration file is the `--config` path,
5+//! then `IM_CONFIG`, then `config/im.toml`. Exit status 0 is success, 1 a failure, 2 a usage error.
2 6
3-fn main() {7+mod assets;
4- println!("im");8+mod boot;
9+mod health;
10+mod i18n;
11+mod live;
12+mod pages;
13+mod security;
14+mod state;
15+mod views;
16+
17+use std::path::{Path, PathBuf};
18+use std::process::ExitCode;
19+
20+use tracing_subscriber::EnvFilter;
21+
22+/// Printed with a usage error.
23+const USAGE: &str = "usage: im [--config <path>] [serve]";
24+
25+/// The configuration file when neither `--config` nor `IM_CONFIG` names one.
26+const DEFAULT_CONFIG: &str = "config/im.toml";
27+
28+/// The environment variable that names the configuration file.
29+const CONFIG_ENV: &str = "IM_CONFIG";
30+
31+/// The parsed command line: the `--config` path and the positional words.
32+struct Cli {
33+ config: Option<PathBuf>,
34+ words: Vec<String>,
35+}
36+
37+/// Splits the arguments into the `--config <path>` pair and the positional words.
38+fn parse_args(args: impl Iterator<Item = String>) -> Result<Cli, String> {
39+ let mut config = None;
40+ let mut words = Vec::new();
41+ let mut args = args;
42+ while let Some(arg) = args.next() {
43+ if arg == "--config" {
44+ let path = args.next().ok_or("--config needs a path")?;
45+ config = Some(PathBuf::from(path));
46+ } else {
47+ words.push(arg);
48+ }
49+ }
50+ Ok(Cli { config, words })
51+}
52+
53+/// The configuration path: the flag, else `IM_CONFIG`, else the default.
54+fn config_path(flag: Option<PathBuf>) -> PathBuf {
55+ flag.or_else(|| std::env::var_os(CONFIG_ENV).map(PathBuf::from))
56+ .unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG))
57+}
58+
59+/// Logs to stderr. The level comes from `RUST_LOG`, and defaults to `info`.
60+fn init_logging() {
61+ let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
62+ tracing_subscriber::fmt()
63+ .with_env_filter(filter)
64+ .with_writer(std::io::stderr)
65+ .init();
66+}
67+
68+/// Runs the server and maps its outcome to an exit status.
69+async fn serve(config: &Path) -> ExitCode {
70+ match boot::serve(config).await {
71+ Ok(()) => ExitCode::SUCCESS,
72+ Err(error) => {
73+ tracing::error!(error = %error, "im stopped with an error");
74+ ExitCode::FAILURE
75+ }
76+ }
77+}
78+
79+#[tokio::main]
80+async fn main() -> ExitCode {
81+ init_logging();
82+ let cli = match parse_args(std::env::args().skip(1)) {
83+ Ok(cli) => cli,
84+ Err(message) => {
85+ eprintln!("im: {message}\n{USAGE}");
86+ return ExitCode::from(2);
87+ }
88+ };
89+ let words: Vec<&str> = cli.words.iter().map(String::as_str).collect();
90+ match words.as_slice() {
91+ [] | ["serve"] => serve(&config_path(cli.config)).await,
92+ ["admin", ..] => {
93+ eprintln!("im: admin commands are not implemented yet");
94+ ExitCode::from(2)
95+ }
96+ _ => {
97+ eprintln!("im: unknown command\n{USAGE}");
98+ ExitCode::from(2)
99+ }
100+ }
5 }101 }
crates/im-web/src/pages/home.rsadded+26 -0
@@ -0,0 +1,26 @@
1+//! The start page. For now it only shows that the server runs; it becomes the account home once
2+//! sign-in exists.
3+
4+use topcoat::Result;
5+use topcoat::context::Cx;
6+use topcoat::router::page;
7+use topcoat::view::{View, view};
8+
9+use crate::i18n::lang;
10+use crate::i18n::shell::{K, t};
11+use crate::views::{notice, shell};
12+
13+/// `GET /`.
14+#[page("/")]
15+async fn home(cx: &Cx) -> Result<impl View> {
16+ let lang = lang(cx, None);
17+ Ok(view! {
18+ shell(title: t(lang, K::ImIsRunning), lang: lang, viewer: None,
19+ <section class="card">
20+ <p class="kicker">"im"</p>
21+ <h1>(t(lang, K::ImIsRunning))</h1>
22+ notice(message: t(lang, K::RunningBody))
23+ </section>
24+ )
25+ })
26+}
crates/im-web/src/pages/mod.rsadded+4 -0
@@ -0,0 +1,4 @@
1+//! The pages and the page-level layers. One file per page.
2+
3+pub mod home;
4+pub mod not_found;
crates/im-web/src/pages/not_found.rsadded+74 -0
@@ -0,0 +1,74 @@
1+//! The styled 404 page. Topcoat answers an unknown path with a bare text body. For a browser
2+//! (`Accept` names `text/html`) the layer below rewrites that answer to a page in the regular
3+//! shell. Other clients keep the plain 404, and so does any request whose path exists.
4+
5+use http::header::ACCEPT;
6+use topcoat::Result;
7+use topcoat::context::Cx;
8+use topcoat::router::error::{NotFoundError, rewrite};
9+use topcoat::router::page;
10+use topcoat::router::request::headers;
11+use topcoat::router::response::Response;
12+use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, StatusCode};
13+use topcoat::view::{View, component, view};
14+
15+use crate::i18n::shell::{K, t};
16+use crate::i18n::{Lang, lang};
17+use crate::views::{empty_state, shell};
18+
19+/// Where a browser's 404 is sent. The page below answers with status 404 itself.
20+const NOT_FOUND_PATH: &str = "/-/not-found";
21+
22+/// Rewrites a 404 for a browser to the styled page. Pathless, so it sees every request.
23+pub struct NotFoundLayer;
24+
25+impl Layer for NotFoundLayer {
26+ fn path(&self) -> Option<&Path> {
27+ None
28+ }
29+
30+ fn handle<'a>(&'a self, cx: &'a Cx, body: Body, next: Next<'a>) -> LayerFuture<'a> {
31+ Box::pin(styled_not_found(cx, body, next))
32+ }
33+}
34+
35+/// Runs the rest of the chain. If it ended in a 404 and the client asked for HTML, the request is
36+/// rewritten to [`NOT_FOUND_PATH`]. Every other outcome is returned unchanged.
37+async fn styled_not_found(cx: &Cx, body: Body, next: Next<'_>) -> Result<Response> {
38+ let result = next.run(cx, body).await;
39+ let missing = matches!(&result, Err(error) if error.downcast_ref::<NotFoundError>().is_some());
40+ let wants_html = headers(cx)
41+ .get(ACCEPT)
42+ .and_then(|value| value.to_str().ok())
43+ .is_some_and(|value| value.contains("text/html"));
44+ if !missing || !wants_html {
45+ return result;
46+ }
47+ Err(rewrite(NOT_FOUND_PATH, Body::empty())
48+ .method(Method::GET)
49+ .into())
50+}
51+
52+/// The 404 page itself.
53+#[page("/-/not-found")]
54+async fn not_found_page(cx: &Cx) -> Result<impl View> {
55+ let lang = lang(cx, None);
56+ Ok(view! {
57+ (StatusCode::NOT_FOUND)
58+ shell(title: t(lang, K::NotFoundTitle), lang: lang, viewer: None, not_found_body(lang: lang))
59+ })
60+}
61+
62+/// The 404 content: the code, then the empty-state card with the explanation and a way back.
63+#[component]
64+async fn not_found_body(lang: Lang) -> Result<impl View> {
65+ Ok(view! {
66+ <section class="not-found">
67+ <p class="not-found-code">"404"</p>
68+ empty_state(title: t(lang, K::NotFoundTitle),
69+ <p>(t(lang, K::NotFoundBody))</p>
70+ <a class="button primary" href="/">(t(lang, K::BackHome))</a>
71+ )
72+ </section>
73+ })
74+}
crates/im-web/src/security.rsadded+85 -0
@@ -0,0 +1,85 @@
1+//! The security headers of every response, and the Content-Security-Policy they carry.
2+//!
3+//! The policy allows scripts and styles from the origin itself and nothing else. No page may use an
4+//! inline script, an inline style or an inline event handler: all behaviour lives in
5+//! `crates/im-web/assets/*.js`. Changing [`CSP`] is a security change, so keep it in step with
6+//! `docs/conventions.md` section 5.
7+
8+use topcoat::context::Cx;
9+use topcoat::router::response::response_headers;
10+use topcoat::router::{Body, HeaderMap, HeaderValue, Layer, LayerFuture, Next, Path, header};
11+
12+/// The Content-Security-Policy of every response.
13+pub const CSP: &str = "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; \
14+ form-action 'self'; frame-ancestors 'none'; base-uri 'none'";
15+
16+/// One year, in seconds. Sent only when the public origin is https.
17+const HSTS: &str = "max-age=31536000";
18+
19+/// The headers that every response carries, for an instance at `base_url`.
20+pub fn headers_for(base_url: &str) -> HeaderMap {
21+ let mut headers = HeaderMap::new();
22+ headers.insert(
23+ header::X_CONTENT_TYPE_OPTIONS,
24+ HeaderValue::from_static("nosniff"),
25+ );
26+ headers.insert(header::X_FRAME_OPTIONS, HeaderValue::from_static("DENY"));
27+ headers.insert(
28+ header::REFERRER_POLICY,
29+ HeaderValue::from_static("same-origin"),
30+ );
31+ headers.insert(
32+ header::CONTENT_SECURITY_POLICY,
33+ HeaderValue::from_static(CSP),
34+ );
35+ if base_url.starts_with("https://") {
36+ headers.insert(
37+ header::STRICT_TRANSPORT_SECURITY,
38+ HeaderValue::from_static(HSTS),
39+ );
40+ }
41+ headers
42+}
43+
44+/// Adds a fixed set of headers to every response of the router.
45+///
46+/// It uses the per-request response headers, which the router applies after the layers have run,
47+/// so error responses (404, 500) carry them as well.
48+pub struct SecurityHeaders {
49+ headers: HeaderMap,
50+}
51+
52+impl SecurityHeaders {
53+ /// A layer that adds `headers` to every response.
54+ pub fn new(headers: HeaderMap) -> Self {
55+ Self { headers }
56+ }
57+}
58+
59+impl Layer for SecurityHeaders {
60+ fn path(&self) -> Option<&Path> {
61+ None
62+ }
63+
64+ fn handle<'a>(&'a self, cx: &'a Cx, body: Body, next: Next<'a>) -> LayerFuture<'a> {
65+ Box::pin(async move {
66+ response_headers(cx).extend(self.headers.clone());
67+ next.run(cx, body).await
68+ })
69+ }
70+}
71+
72+#[cfg(test)]
73+mod tests {
74+ use super::*;
75+
76+ #[test]
77+ fn hsts_only_for_https_origins() {
78+ assert!(
79+ headers_for("https://im.example.com").contains_key(header::STRICT_TRANSPORT_SECURITY)
80+ );
81+ assert!(
82+ !headers_for("http://127.0.0.1:7650").contains_key(header::STRICT_TRANSPORT_SECURITY)
83+ );
84+ }
85+}
crates/im-web/src/state.rsadded+22 -0
@@ -0,0 +1,22 @@
1+//! The state shared by every route. Topcoat hands it to each handler through the app context.
2+
3+use std::sync::Arc;
4+
5+use im_core::config::Config;
6+use im_core::store::Store;
7+
8+use crate::live::LiveHub;
9+
10+/// Everything a request handler reaches through the app context. Every field is cheap to clone.
11+#[allow(dead_code)] // The key and the hub are read by the sign-in and live pages that come next.
12+#[derive(Clone)]
13+pub struct AppState {
14+ /// The configuration the process booted with.
15+ pub config: Arc<Config>,
16+ /// The database. Reads go to a pooled reader and writes to the single writer.
17+ pub store: Store,
18+ /// The instance key (`im.key`). Seals secrets at rest.
19+ pub key: Arc<[u8; 32]>,
20+ /// The change counters of the live pages.
21+ pub live: Arc<LiveHub>,
22+}
crates/im-web/src/views/mod.rsadded+89 -0
@@ -0,0 +1,89 @@
1+//! Shared page chrome: the HTML shell and the small components every page is built from.
2+//!
3+//! `view!` escapes text and attribute values, so user data is safe in it by default. Nothing here
4+//! emits an inline script, style or event handler; see `security.rs`.
5+
6+use topcoat::Result;
7+use topcoat::view::{Child, View, component, view};
8+
9+use crate::assets::{MAIN_CSS_HREF, NAV_JS_HREF, PAGES_JS_HREF};
10+use crate::i18n::Lang;
11+use crate::i18n::shell::{K, t};
12+
13+/// What the shell shows about the signed-in person. Nothing signs a person in yet, so every page
14+/// is built for an anonymous viewer.
15+#[allow(dead_code)] // Built by the sign-in code, which comes next.
16+pub struct ViewerInfo {
17+ /// The name shown in the topbar.
18+ pub name: String,
19+ /// Whether the topbar shows the administrator badge.
20+ pub is_admin: bool,
21+}
22+
23+/// The HTML document around a page. `title` is the page's own title; the document title adds the
24+/// app name. `child` is the page, placed in `<main>`.
25+///
26+/// The topbar has the wordmark on the left, the service switcher in the middle (empty for now) and
27+/// the viewer's name on the right. `nav.js` reads the restart text from `<body data-restart-text>`.
28+#[component]
29+pub async fn shell(
30+ title: &str,
31+ lang: Lang,
32+ viewer: Option<&ViewerInfo>,
33+ #[default] child: Child<'_>,
34+) -> Result<impl View> {
35+ let document_title = format!("{title} \u{b7} im");
36+ Ok(view! {
37+ <!DOCTYPE html>
38+ <html lang=(lang.code()) data-theme="system">
39+ <head>
40+ <meta charset="utf-8">
41+ <meta name="viewport" content="width=device-width, initial-scale=1">
42+ <title>(document_title)</title>
43+ <link rel="stylesheet" href=(MAIN_CSS_HREF)>
44+ <script src=(NAV_JS_HREF) defer=""></script>
45+ <script src=(PAGES_JS_HREF) defer=""></script>
46+ </head>
47+ <body data-restart-text=(t(lang, K::ServerRestarting))>
48+ <a class="skip-link" href="#main">(t(lang, K::SkipToContent))</a>
49+ <header class="topbar">
50+ <a class="topbar-brand" href="/">"im"</a>
51+ <nav class="switcher" aria-label=(t(lang, K::Services))></nav>
52+ <div class="topbar-end">
53+ if let Some(viewer) = viewer {
54+ <span>(viewer.name.as_str())</span>
55+ if viewer.is_admin {
56+ <span class="badge accent">(t(lang, K::Admin))</span>
57+ }
58+ }
59+ </div>
60+ </header>
61+ <main id="main">(child)</main>
62+ </body>
63+ </html>
64+ })
65+}
66+
67+/// An error message for a failed action. Forms show it above their fields.
68+#[allow(dead_code)] // The first form that can fail a check uses it.
69+#[component]
70+pub async fn alert(message: &str) -> Result<impl View> {
71+ Ok(view! { <div class="alert" role="alert">(message)</div> })
72+}
73+
74+/// A plain message that is not an error, such as a confirmation or a hint.
75+#[component]
76+pub async fn notice(message: &str) -> Result<impl View> {
77+ Ok(view! { <div class="notice" role="status">(message)</div> })
78+}
79+
80+/// A section with nothing in it yet: a title, then what to do next.
81+#[component]
82+pub async fn empty_state(title: &str, #[default] child: Child<'_>) -> Result<impl View> {
83+ Ok(view! {
84+ <section class="empty-state">
85+ <h2>(title)</h2>
86+ (child)
87+ </section>
88+ })
89+}
docs/attack-plan.mdadded+71 -0
@@ -0,0 +1,71 @@
1+# Attack plan
2+
3+How `im` (first), `in` and `iz` are attacked after each build step. Every finding becomes a fix commit plus,
4+when cheap, one regression test. Attacks run only against local instances on `127.0.0.1` with scratch data.
5+
6+## 1. im: authentication
7+
8+- Login: username enumeration by message, status, timing (unknown vs wrong password vs disabled); throttle
9+ bypass (case/whitespace variants of the email, IPv6 /64 rotation, `X-Forwarded-For` spoofing without a
10+ trusted proxy); throttle memory growth with random keys.
11+- Pre-CSRF: login without the cookie/field, with mismatched values, cross-site form post.
12+- 2FA: skip `/login/2fa` by going to `/` with the pending cookie; tamper/replay the pending cookie; reuse a TOTP
13+ step; brute force within the window; recovery code reuse and race (two parallel submissions).
14+- Sessions: fixation (does login rotate the token?), cookie flags, logout really deletes, revoked session still
15+ works on live streams, `max_sessions` race.
16+- Password reset / invite / email change: token reuse, parallel redemption race, expired token, token for
17+ another user, enumeration through `/forgot`, links leaking into logs or redirects, email change to a taken
18+ address at confirm time, confirm only one half.
19+- Setup: `/setup` after the first user exists; two parallel setups.
20+
21+## 2. im: OIDC
22+
23+- `/authorize`: open redirect via `redirect_uri` (prefix, case, trailing slash, userinfo `@`, encoded chars,
24+ fragments), missing/plain PKCE, `response_type` other than `code`, scope injection, `state`/`nonce` echo
25+ injection (XSS in error page), unknown/disabled client.
26+- `/token`: code reuse (must revoke the family), code for another client, wrong `redirect_uri`, wrong verifier,
27+ expired code, client auth with the wrong secret, both basic and post at once, oversized bodies.
28+- Refresh: reuse of a rotated token (family revocation), refresh after logout/disable, refresh for another
29+ client.
30+- Client credentials: scopes beyond `allowed_scopes`, `audience` not a family key, disabled client.
31+- JWT: `alg: none`, alg confusion, unknown `kid`, expired, `aud` array tricks, signature of another key,
32+ retired key still accepted after 7 days.
33+- `/userinfo`, `/introspect`, `/revoke`: token of another client, revoked tokens.
34+- Back-channel: does every session end reach every client; is the outbox retried; does a failure block logout.
35+- `/logout`: `post_logout_redirect_uri` not registered (open redirect), missing `id_token_hint`.
36+
37+## 3. im: machine APIs
38+
39+- Directory/photo/family without a token, with a user access token instead of a client token, with the wrong
40+ audience or scope, with an expired token.
41+- Stream: cursor from the future, negative, huge; resync path; connection exhaustion.
42+- Photo: path traversal in `{sub}`, huge upload, polyglot image (HTML/SVG in a PNG), content-type served.
43+
44+## 4. im: web
45+
46+- CSRF on every POST (missing, wrong, other session's token).
47+- Authorization: every admin route as a member and as anonymous (expect 404); last-admin demotion/disable;
48+ self-disable; IDOR on sessions/apps revoke (another user's id).
49+- XSS: names, emails, client names, service names, user agents, audit data rendered everywhere (including the
50+ admin pages and mails); CSP effectiveness.
51+- Headers on every response type (pages, JSON, SSE, assets, errors).
52+- Input limits: very long names, emails, passwords (argon2 cost DoS), huge forms, unicode tricks (homoglyph
53+ emails, RTL override in names, NUL bytes).
54+- `safe_next` bypasses on every `next` parameter.
55+- Live: streams leak other users' data or keep running after sign-out.
56+
57+## 5. Operational
58+
59+- Kill the process mid-write; restart; integrity check. Disk full during photo upload.
60+- Backup → restore → compare. Restore refuses a tampered set.
61+- Config: unknown keys, missing file, bad values, secret files with loose permissions.
62+- Concurrency: 50 parallel logins, 20 parallel token exchanges with one code, SQLite busy errors surfacing as
63+ 500s.
64+
65+## 6. in and iz
66+
67+The same web, CSRF, authz, XSS and header checks, plus: path traversal in names and blob keys, quota races with
68+parallel uploads, chunk index/size abuse, Range header abuse, share-link password brute force, grant leakage
69+through folder moves, trashed items reachable by grantees or links, service object namespace escape, iz role
70+escalation, viewer writes, cross-task IDOR on attachments/comments, mail header injection via names and
71+subjects, rule loops, reminder spam, zip bombs in sheet/slides viewers, SVG/HTML served inline.
style/_base.scssadded+117 -0
@@ -0,0 +1,117 @@
1+//! Element defaults: the reset, the body type, links, headings and focus. Nothing here is a class;
2+//! a page gets its look from elements it writes plainly, and from the component classes.
3+
4+*,
5+*::before,
6+*::after {
7+ box-sizing: border-box;
8+}
9+
10+html {
11+ -webkit-text-size-adjust: 100%;
12+ text-size-adjust: 100%;
13+}
14+
15+body {
16+ margin: 0;
17+ background: var(--bg);
18+ color: var(--text);
19+ font-family: var(--font-sans);
20+ font-size: 1rem;
21+ line-height: 1.55;
22+ -webkit-font-smoothing: antialiased;
23+}
24+
25+h1,
26+h2,
27+h3 {
28+ line-height: 1.25;
29+ margin: 0 0 var(--space-3);
30+ font-weight: 650;
31+ letter-spacing: -0.01em;
32+}
33+
34+h1 {
35+ font-size: var(--text-xl);
36+}
37+
38+h2 {
39+ font-size: var(--text-lg);
40+}
41+
42+h3 {
43+ font-size: 1rem;
44+}
45+
46+p {
47+ margin: 0 0 var(--space-3);
48+}
49+
50+a {
51+ color: var(--accent);
52+ text-decoration-thickness: 1px;
53+ text-underline-offset: 0.2em;
54+}
55+
56+a:hover {
57+ color: var(--accent-strong);
58+}
59+
60+img,
61+svg {
62+ display: block;
63+ max-width: 100%;
64+}
65+
66+code,
67+kbd,
68+pre {
69+ font-family: var(--font-mono);
70+ font-size: 0.92em;
71+}
72+
73+:focus-visible {
74+ outline: 2px solid var(--focus);
75+ outline-offset: 2px;
76+ border-radius: 2px;
77+}
78+
79+::selection {
80+ background: var(--accent-soft);
81+}
82+
83+// The `hidden` attribute must win over any display rule a component sets.
84+[hidden] {
85+ display: none !important;
86+}
87+
88+// Visible only to screen readers.
89+.sr-only {
90+ position: absolute;
91+ width: 1px;
92+ height: 1px;
93+ padding: 0;
94+ margin: -1px;
95+ overflow: hidden;
96+ clip: rect(0, 0, 0, 0);
97+ white-space: nowrap;
98+ border: 0;
99+}
100+
101+// The first focusable element. It is off screen until a keyboard user tabs to it.
102+.skip-link {
103+ position: absolute;
104+ top: var(--space-2);
105+ left: var(--space-2);
106+ z-index: 100;
107+ padding: var(--space-2) var(--space-3);
108+ background: var(--surface);
109+ color: var(--text);
110+ border-radius: var(--radius-sm);
111+ box-shadow: var(--shadow-lift);
112+ transform: translateY(-200%);
113+}
114+
115+.skip-link:focus {
116+ transform: none;
117+}
style/_components.scssadded+315 -0
@@ -0,0 +1,315 @@
1+//! Components: buttons, form controls, cards, alerts, tables, badges, the empty state, the 404 page
2+//! and the "server restarting" bar. Each is one class (or one element) with its states.
3+
4+// --- Buttons -----------------------------------------------------------------------------------
5+
6+.button {
7+ display: inline-flex;
8+ align-items: center;
9+ justify-content: center;
10+ gap: var(--space-2);
11+ min-height: 2.25rem;
12+ padding: var(--space-2) var(--space-4);
13+ border: 1px solid var(--border);
14+ border-radius: var(--radius-sm);
15+ background: var(--surface);
16+ color: var(--text);
17+ font: inherit;
18+ font-weight: 550;
19+ text-decoration: none;
20+ cursor: pointer;
21+ box-shadow: var(--shadow);
22+ transition: background-color 120ms ease, border-color 120ms ease;
23+}
24+
25+.button:hover {
26+ background: var(--surface-2);
27+ color: var(--text);
28+}
29+
30+.button:disabled,
31+.button[aria-disabled="true"] {
32+ opacity: 0.55;
33+ cursor: not-allowed;
34+}
35+
36+.button.primary {
37+ background: var(--accent);
38+ border-color: var(--accent);
39+ color: var(--accent-text);
40+}
41+
42+.button.primary:hover {
43+ background: var(--accent-strong);
44+ border-color: var(--accent-strong);
45+ color: var(--accent-text);
46+}
47+
48+.button.danger {
49+ color: var(--danger);
50+ border-color: var(--danger);
51+}
52+
53+.button.ghost {
54+ background: transparent;
55+ box-shadow: none;
56+ border-color: transparent;
57+}
58+
59+// --- Form controls ----------------------------------------------------------------------------
60+
61+label {
62+ display: block;
63+ font-weight: 550;
64+ font-size: var(--text-sm);
65+ margin-bottom: var(--space-1);
66+}
67+
68+input:not([type="checkbox"]):not([type="radio"]),
69+select,
70+textarea {
71+ width: 100%;
72+ min-height: 2.25rem;
73+ padding: var(--space-2) var(--space-3);
74+ border: 1px solid var(--border);
75+ border-radius: var(--radius-sm);
76+ background: var(--surface);
77+ color: var(--text);
78+ font: inherit;
79+}
80+
81+textarea {
82+ min-height: 6rem;
83+ resize: vertical;
84+}
85+
86+input:focus,
87+select:focus,
88+textarea:focus {
89+ outline: 2px solid var(--focus);
90+ outline-offset: 0;
91+ border-color: transparent;
92+}
93+
94+input::placeholder,
95+textarea::placeholder {
96+ color: var(--muted);
97+ opacity: 0.8;
98+}
99+
100+.field {
101+ display: grid;
102+ gap: var(--space-1);
103+}
104+
105+.field + .field {
106+ margin-top: var(--space-4);
107+}
108+
109+.field-hint {
110+ color: var(--muted);
111+ font-size: var(--text-sm);
112+}
113+
114+// --- Cards and text ---------------------------------------------------------------------------
115+
116+.card {
117+ padding: var(--space-6);
118+ background: var(--surface);
119+ border: 1px solid var(--border);
120+ border-radius: var(--radius);
121+ box-shadow: var(--shadow);
122+}
123+
124+.card > :last-child {
125+ margin-bottom: 0;
126+}
127+
128+.card-title {
129+ margin-bottom: var(--space-2);
130+}
131+
132+.muted {
133+ color: var(--muted);
134+}
135+
136+.kicker {
137+ margin-bottom: var(--space-2);
138+ color: var(--muted);
139+ font-size: var(--text-sm);
140+ font-weight: 600;
141+ letter-spacing: 0.04em;
142+ text-transform: uppercase;
143+}
144+
145+// --- Alerts -----------------------------------------------------------------------------------
146+
147+.alert,
148+.notice {
149+ padding: var(--space-3) var(--space-4);
150+ border-radius: var(--radius-sm);
151+ border: 1px solid transparent;
152+}
153+
154+.alert {
155+ background: var(--danger-soft);
156+ color: var(--danger);
157+ border-color: var(--danger);
158+}
159+
160+.notice {
161+ background: var(--accent-soft);
162+ color: var(--text);
163+ border-color: var(--accent-soft);
164+}
165+
166+// --- Tables and badges ------------------------------------------------------------------------
167+
168+.table-wrap {
169+ overflow-x: auto;
170+ border: 1px solid var(--border);
171+ border-radius: var(--radius);
172+ background: var(--surface);
173+}
174+
175+.table {
176+ width: 100%;
177+ border-collapse: collapse;
178+ font-size: var(--text-sm);
179+}
180+
181+.table th,
182+.table td {
183+ padding: var(--space-2) var(--space-3);
184+ text-align: left;
185+ border-bottom: 1px solid var(--border);
186+ vertical-align: top;
187+}
188+
189+.table th {
190+ color: var(--muted);
191+ font-weight: 600;
192+ background: var(--surface-2);
193+}
194+
195+.table tr:last-child td {
196+ border-bottom: 0;
197+}
198+
199+.badge {
200+ display: inline-block;
201+ padding: 0.1rem var(--space-2);
202+ border-radius: 999px;
203+ background: var(--surface-2);
204+ color: var(--muted);
205+ font-size: 0.8rem;
206+ font-weight: 600;
207+ white-space: nowrap;
208+}
209+
210+.badge.accent {
211+ background: var(--accent-soft);
212+ color: var(--accent-strong);
213+}
214+
215+// --- Empty state and the 404 page -------------------------------------------------------------
216+
217+.empty-state {
218+ display: grid;
219+ justify-items: center;
220+ gap: var(--space-3);
221+ padding: var(--space-8) var(--space-6);
222+ text-align: center;
223+ color: var(--muted);
224+ border: 1px dashed var(--border);
225+ border-radius: var(--radius);
226+}
227+
228+.empty-state h2 {
229+ margin: 0;
230+ color: var(--text);
231+}
232+
233+.empty-state p {
234+ margin: 0;
235+ max-width: 34rem;
236+}
237+
238+.not-found {
239+ text-align: center;
240+ padding-block: var(--space-8);
241+}
242+
243+.not-found-code {
244+ margin: 0;
245+ font-size: 3.5rem;
246+ font-weight: 700;
247+ letter-spacing: -0.03em;
248+ color: var(--accent);
249+ line-height: 1;
250+}
251+
252+// --- Server restarting bar --------------------------------------------------------------------
253+
254+// Pinned to the bottom edge. nav.js creates it only while the server is unreachable, so a page
255+// that never loses the server never shows it.
256+.restart-bar {
257+ position: fixed;
258+ left: 50%;
259+ bottom: var(--space-4);
260+ z-index: 50;
261+ transform: translateX(-50%);
262+ display: flex;
263+ align-items: center;
264+ gap: var(--space-3);
265+ max-width: calc(100vw - 2 * var(--space-4));
266+ padding: var(--space-2) var(--space-4);
267+ border-radius: 999px;
268+ background: var(--warn-soft);
269+ color: var(--warn);
270+ border: 1px solid var(--warn);
271+ box-shadow: var(--shadow-lift);
272+ font-size: var(--text-sm);
273+ font-weight: 550;
274+ animation: restart-in 180ms ease-out;
275+}
276+
277+.restart-bar::before {
278+ content: "";
279+ width: 0.55rem;
280+ height: 0.55rem;
281+ border-radius: 50%;
282+ background: currentColor;
283+ animation: restart-pulse 1.2s ease-in-out infinite;
284+}
285+
286+@keyframes restart-in {
287+ from {
288+ opacity: 0;
289+ transform: translate(-50%, 0.5rem);
290+ }
291+}
292+
293+@keyframes restart-pulse {
294+ 50% {
295+ opacity: 0.25;
296+ }
297+}
298+
299+// While the page is loading a soft navigation or a refresh, its content dims a little.
300+.is-loading main {
301+ opacity: 0.6;
302+ transition: opacity 120ms ease;
303+}
304+
305+@media (prefers-reduced-motion: reduce) {
306+ .restart-bar,
307+ .restart-bar::before {
308+ animation: none;
309+ }
310+
311+ .is-loading main,
312+ .button {
313+ transition: none;
314+ }
315+}
style/_layout.scssadded+110 -0
@@ -0,0 +1,110 @@
1+//! Page frame: the sticky top bar (wordmark, service switcher, right-hand slot) and the main column.
2+//! Below 720 px the top bar wraps onto two rows and the card grid goes to one column.
3+
4+.topbar {
5+ position: sticky;
6+ top: 0;
7+ z-index: 20;
8+ display: flex;
9+ align-items: center;
10+ gap: var(--space-4);
11+ min-height: 3.25rem;
12+ padding: var(--space-2) var(--space-6);
13+ background: var(--topbar);
14+ backdrop-filter: saturate(1.4) blur(8px);
15+ border-bottom: 1px solid var(--border);
16+}
17+
18+.topbar-brand {
19+ display: inline-flex;
20+ align-items: baseline;
21+ gap: var(--space-2);
22+ color: var(--text);
23+ font-weight: 700;
24+ font-size: var(--text-lg);
25+ text-decoration: none;
26+ letter-spacing: -0.02em;
27+}
28+
29+.topbar-brand:hover {
30+ color: var(--accent);
31+}
32+
33+// The service switcher fills the middle of the bar. It is empty until there are services to list.
34+.switcher {
35+ display: flex;
36+ align-items: center;
37+ flex: 1 1 auto;
38+ gap: var(--space-1);
39+ min-width: 0;
40+ overflow-x: auto;
41+}
42+
43+.switcher:empty {
44+ display: none;
45+}
46+
47+.switcher a {
48+ padding: var(--space-1) var(--space-3);
49+ border-radius: var(--radius-sm);
50+ color: var(--muted);
51+ text-decoration: none;
52+ white-space: nowrap;
53+}
54+
55+.switcher a[aria-current="page"],
56+.switcher a:hover {
57+ background: var(--surface-2);
58+ color: var(--text);
59+}
60+
61+.topbar-end {
62+ display: flex;
63+ align-items: center;
64+ gap: var(--space-3);
65+ margin-left: auto;
66+ color: var(--muted);
67+ font-size: var(--text-sm);
68+}
69+
70+.page {
71+ width: 100%;
72+ max-width: var(--content-width);
73+ margin: 0 auto;
74+ padding: var(--space-8) var(--space-6) var(--space-8);
75+}
76+
77+.page > * + * {
78+ margin-top: var(--space-6);
79+}
80+
81+.grid-cards {
82+ display: grid;
83+ grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
84+ gap: var(--space-4);
85+}
86+
87+@media (max-width: 720px) {
88+ .topbar {
89+ flex-wrap: wrap;
90+ gap: var(--space-2) var(--space-3);
91+ padding: var(--space-2) var(--space-4);
92+ }
93+
94+ .switcher {
95+ order: 3;
96+ flex-basis: 100%;
97+ }
98+
99+ .topbar-end {
100+ margin-left: 0;
101+ }
102+
103+ .page {
104+ padding: var(--space-6) var(--space-4);
105+ }
106+
107+ .grid-cards {
108+ grid-template-columns: 1fr;
109+ }
110+}
style/_tokens.scssadded+90 -0
@@ -0,0 +1,90 @@
1+//! Design tokens: the colours of the light and dark themes, spacing, radii and type. Every other
2+//! partial reads these custom properties, so a theme changes in one place.
3+//!
4+//! Dark applies in two cases. The OS asks for it (`prefers-color-scheme: dark`) and the page is not
5+//! forced to light, or the page sets `data-theme="dark"`. `data-theme="light"` forces light whatever
6+//! the OS says. The dark rules carry one more attribute than the light ones, so they win on the same
7+//! element without `!important`.
8+
9+/// The light palette. Contrast of `--text` on `--bg` and `--surface` is above 7:1.
10+@mixin light-tokens {
11+ --bg: #f5f5f2;
12+ --surface: #ffffff;
13+ --surface-2: #eeeeea;
14+ --text: #1c1e22;
15+ --muted: #5b6070;
16+ --border: #d9dbe0;
17+ --accent: #3350c4;
18+ --accent-strong: #2a43a8;
19+ --accent-text: #ffffff;
20+ --accent-soft: #e6ebff;
21+ --danger: #b42318;
22+ --danger-soft: #fdecea;
23+ --warn: #7a4f00;
24+ --warn-soft: #fff4d6;
25+ --ok: #1e7a3a;
26+ --ok-soft: #e4f4ea;
27+ --focus: #3350c4;
28+ --topbar: #ffffffe6;
29+}
30+
31+/// The dark palette. Same roles as the light one.
32+@mixin dark-tokens {
33+ --bg: #111215;
34+ --surface: #1a1c21;
35+ --surface-2: #22252c;
36+ --text: #e8eaef;
37+ --muted: #a1a7b5;
38+ --border: #2d3139;
39+ --accent: #9fb2ff;
40+ --accent-strong: #c2d0ff;
41+ --accent-text: #0d1220;
42+ --accent-soft: #1f2a4f;
43+ --danger: #ff8a80;
44+ --danger-soft: #3a1d1b;
45+ --warn: #f2c265;
46+ --warn-soft: #3a2e10;
47+ --ok: #7fd09a;
48+ --ok-soft: #173424;
49+ --focus: #9fb2ff;
50+ --topbar: #1a1c21e6;
51+}
52+
53+:root {
54+ color-scheme: light;
55+ @include light-tokens;
56+
57+ --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
58+ sans-serif;
59+ --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
60+
61+ --radius: 10px;
62+ --radius-sm: 6px;
63+ --shadow: 0 1px 2px rgb(0 0 0 / 0.06);
64+ --shadow-lift: 0 4px 14px rgb(0 0 0 / 0.08);
65+
66+ --space-1: 0.25rem;
67+ --space-2: 0.5rem;
68+ --space-3: 0.75rem;
69+ --space-4: 1rem;
70+ --space-6: 1.5rem;
71+ --space-8: 2rem;
72+
73+ --text-sm: 0.875rem;
74+ --text-lg: 1.125rem;
75+ --text-xl: 1.5rem;
76+
77+ --content-width: 56rem;
78+}
79+
80+@media (prefers-color-scheme: dark) {
81+ :root:not([data-theme="light"]) {
82+ color-scheme: dark;
83+ @include dark-tokens;
84+ }
85+}
86+
87+:root[data-theme="dark"] {
88+ color-scheme: dark;
89+ @include dark-tokens;
90+}
style/main.scssadded+8 -0
@@ -0,0 +1,8 @@
1+//! The stylesheet of `im`. `build.rs` compiles this file with grass into `OUT_DIR/main.css`, and the
2+//! binary embeds the result. The order matters: tokens first, then the element defaults, the layout
3+//! and the components that use the tokens.
4+
5+@use "tokens";
6+@use "base";
7+@use "layout";
8+@use "components";