From 886a82b1ad512cc6054089950aab3aafead96cac Mon Sep 17 00:00:00 2001 From: Melody Leonard Date: Sat, 21 Feb 2026 21:32:05 -0500 Subject: [PATCH 1/5] first implementation for webhook --- .env.example | 4 + Cargo.lock | 1623 +++++++++++++++++++++++++++++ Cargo.toml | 14 +- Dockerfile | 25 + README.md | 10 + crates/domain/Cargo.toml | 10 + crates/domain/src/lib.rs | 4 + crates/domain/src/transaction.rs | 67 ++ crates/queue/Cargo.toml | 11 + crates/queue/src/lib.rs | 97 ++ crates/rpc-client/Cargo.toml | 15 + crates/rpc-client/src/lib.rs | 129 +++ crates/webhook-server/Cargo.toml | 13 + crates/webhook-server/src/main.rs | 92 ++ crates/worker/Cargo.toml | 14 + crates/worker/src/main.rs | 98 ++ docker-compose.yml | 22 + scripts/coverage.sh | 9 + scripts/start-all.sh | 9 + scripts/start-webhook-server.sh | 5 + scripts/start-worker.sh | 5 + scripts/test.sh | 5 + src/lib.rs | 14 - 23 files changed, 2276 insertions(+), 19 deletions(-) create mode 100644 .env.example create mode 100644 Cargo.lock create mode 100644 Dockerfile create mode 100644 crates/domain/Cargo.toml create mode 100644 crates/domain/src/lib.rs create mode 100644 crates/domain/src/transaction.rs create mode 100644 crates/queue/Cargo.toml create mode 100644 crates/queue/src/lib.rs create mode 100644 crates/rpc-client/Cargo.toml create mode 100644 crates/rpc-client/src/lib.rs create mode 100644 crates/webhook-server/Cargo.toml create mode 100644 crates/webhook-server/src/main.rs create mode 100644 crates/worker/Cargo.toml create mode 100644 crates/worker/src/main.rs create mode 100644 docker-compose.yml create mode 100644 scripts/coverage.sh create mode 100644 scripts/start-all.sh create mode 100644 scripts/start-webhook-server.sh create mode 100644 scripts/start-worker.sh create mode 100644 scripts/test.sh delete mode 100644 src/lib.rs diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..fb08ffb --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +APP_ENV=staging +BACKEND_STAGING_URL=https://staging.ourpocket.com +BACKEND_PROD_URL=https://api.ourpocket.com + diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..879f246 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1623 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "axum-macros", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d123550fa8d071b7255cb0cc04dc302baa6c8c4a79f55701552684d8399bce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "domain" +version = "0.1.0" +dependencies = [ + "anyhow", + "serde", + "serde_json", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e709f3e3d22866f9c25b3aff01af289b18422cc8b4262fb19103ee80fe513d" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "queue" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "domain", + "serde_json", + "tokio", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rpc-client" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "domain", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1adf1535672f5b7824f817792b1afd731d7e843d2d04ec8f27e8cb51edd8ac" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe88540d1c934c4ec8e6db0afa536876c5441289d7f9f9123d4f065ac1250a6b" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e638317c08b21663aed4d2b9a2091450548954695ff4efa75bff5fa546b3b1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c64760850114d03d5f65457e96fc988f11f01d38fbaa51b254e4ab5809102af" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60eecd4fe26177cfa3339eb00b4a36445889ba3ad37080c2429879718e20ca41" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6bb20ed2d9572df8584f6dc81d68a41a625cadc6f15999d649a70ce7e3597a" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webhook-server" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "domain", + "queue", + "serde_json", + "tokio", + "tower", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + +[[package]] +name = "worker" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "domain", + "dotenvy", + "queue", + "rpc-client", + "serde_json", + "tokio", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 615a5ac..92234cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,10 @@ -[package] -name = "webhook" -version = "0.1.0" -edition = "2024" -[dependencies] +[workspace] +members = [ + "crates/domain", + "crates/webhook-server", + "crates/queue", + "crates/rpc-client", + "crates/worker", +] +resolver = "2" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9332739 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM rust:slim-trixie AS builder + +WORKDIR /app + +# Copy manifests and code +COPY Cargo.toml Cargo.lock ./ +COPY crates ./crates + + +RUN cargo build --release -p webhook-server + +FROM debian:trixie-slim + +RUN useradd -m appuser + + +COPY --from=builder /app/target/release/webhook-server /usr/local/bin/webhook-app + +RUN chmod +x /usr/local/bin/webhook-app && chown appuser:appuser /usr/local/bin/webhook-app + +USER appuser +ENV RUST_LOG=info + + +ENTRYPOINT ["/usr/local/bin/webhook-app"] \ No newline at end of file diff --git a/README.md b/README.md index eeb6b59..e14edae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # webhook Webhook layer for ourpocket. + +## Scripts + +From the project root: + +- `./scripts/start-webhook-server.sh` starts the Axum webhook HTTP server. +- `./scripts/start-worker.sh` starts the worker service. +- `./scripts/start-all.sh` starts both server and worker in the same shell. +- `./scripts/test.sh` runs `cargo test --workspace`. +- `./scripts/coverage.sh` runs coverage with `cargo llvm-cov` if installed. diff --git a/crates/domain/Cargo.toml b/crates/domain/Cargo.toml new file mode 100644 index 0000000..94fc543 --- /dev/null +++ b/crates/domain/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "domain" +version = "0.1.0" +edition = "2024" + +[dependencies] +serde = { version = "1", features = ["derive"] } +serde_json = "1" +anyhow = "1" + diff --git a/crates/domain/src/lib.rs b/crates/domain/src/lib.rs new file mode 100644 index 0000000..11d412a --- /dev/null +++ b/crates/domain/src/lib.rs @@ -0,0 +1,4 @@ +mod transaction; + +pub use transaction::{normalize_payload, TransactionEvent}; + diff --git a/crates/domain/src/transaction.rs b/crates/domain/src/transaction.rs new file mode 100644 index 0000000..15037ac --- /dev/null +++ b/crates/domain/src/transaction.rs @@ -0,0 +1,67 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +pub struct TransactionEvent { + pub transaction_ref: String, + pub user_id: String, + pub application_id: String, + pub status: String, + pub amount: f64, + pub category: String, + pub metadata: serde_json::Value, +} + +pub fn normalize_payload(raw: &str) -> Result { + let json: serde_json::Value = serde_json::from_str(raw)?; + + Ok(TransactionEvent { + transaction_ref: json["transactionRef"] + .as_str() + .unwrap_or("") + .to_string(), + user_id: json["userId"].as_str().unwrap_or("").to_string(), + application_id: json["applicationId"] + .as_str() + .unwrap_or("") + .to_string(), + status: json["status"].as_str().unwrap_or("").to_string(), + amount: json["amount"].as_f64().unwrap_or(0.0), + category: json["category"].as_str().unwrap_or("").to_string(), + metadata: json, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_normalize_payload_basic_fields() { + let raw = r#" + { + "transactionRef": "abc123", + "userId": "user1", + "applicationId": "app1", + "status": "SUCCESS", + "amount": 100.5, + "category": "PAYMENT" + } + "#; + + let event = normalize_payload(raw).expect("normalize_payload should succeed"); + + assert_eq!( + event, + TransactionEvent { + transaction_ref: "abc123".to_string(), + user_id: "user1".to_string(), + application_id: "app1".to_string(), + status: "SUCCESS".to_string(), + amount: 100.5, + category: "PAYMENT".to_string(), + metadata: serde_json::from_str(raw).unwrap() + } + ); + } +} + diff --git a/crates/queue/Cargo.toml b/crates/queue/Cargo.toml new file mode 100644 index 0000000..ae87d74 --- /dev/null +++ b/crates/queue/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "queue" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1" +async-trait = "0.1" +domain = { path = "../domain" } +tokio = { version = "1", features = ["sync"] } +serde_json = "1" diff --git a/crates/queue/src/lib.rs b/crates/queue/src/lib.rs new file mode 100644 index 0000000..e6000b9 --- /dev/null +++ b/crates/queue/src/lib.rs @@ -0,0 +1,97 @@ +use std::sync::Arc; + +use anyhow::Error; +use async_trait::async_trait; +use domain::TransactionEvent; +use tokio::sync::mpsc; + +#[async_trait] +pub trait EventQueue: Send + Sync { + async fn publish(&self, event: TransactionEvent) -> Result<(), Error>; +} + +#[async_trait] +pub trait EventQueueConsumer: Send + Sync { + async fn consume(&self) -> Result; +} + +#[derive(Clone)] +pub struct InMemoryQueue { + sender: mpsc::Sender, + receiver: Arc>>, +} + +impl InMemoryQueue { + pub fn new(buffer: usize) -> Self { + let (sender, receiver) = mpsc::channel(buffer); + Self { + sender, + receiver: Arc::new(tokio::sync::Mutex::new(receiver)), + } + } +} + +#[async_trait] +impl EventQueue for InMemoryQueue { + async fn publish(&self, event: TransactionEvent) -> Result<(), Error> { + self.sender + .send(event) + .await + .map_err(|err| Error::msg(err.to_string())) + } +} + +#[async_trait] +impl EventQueueConsumer for InMemoryQueue { + async fn consume(&self) -> Result { + let mut rx = self.receiver.lock().await; + rx.recv() + .await + .ok_or_else(|| Error::msg("queue closed".to_string())) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn build_event(id: &str) -> TransactionEvent { + TransactionEvent { + transaction_ref: format!("ref-{id}"), + user_id: id.to_string(), + application_id: "app".to_string(), + status: "SUCCESS".to_string(), + amount: 10.0, + category: "TEST".to_string(), + metadata: serde_json::json!({ "id": id }), + } + } + + #[tokio::test] + async fn publish_and_consume_round_trip() { + let queue = InMemoryQueue::new(8); + + let event = build_event("user-1"); + queue + .publish(event.clone()) + .await + .expect("publish should succeed"); + + let consumed = queue.consume().await.expect("consume should succeed"); + assert_eq!(consumed, event); + } + + #[tokio::test] + async fn consume_returns_error_when_queue_closed() { + let (sender, receiver) = mpsc::channel(1); + drop(sender); + + let queue = InMemoryQueue { + sender: mpsc::channel(1).0, + receiver: Arc::new(tokio::sync::Mutex::new(receiver)), + }; + + let result = queue.consume().await; + assert!(result.is_err()); + } +} diff --git a/crates/rpc-client/Cargo.toml b/crates/rpc-client/Cargo.toml new file mode 100644 index 0000000..000a59d --- /dev/null +++ b/crates/rpc-client/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rpc-client" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1" +reqwest = { version = "0.12", default-features = false, features = [ + "json", + "rustls-tls", +] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +domain = { path = "../domain" } +async-trait = "0.1" diff --git a/crates/rpc-client/src/lib.rs b/crates/rpc-client/src/lib.rs new file mode 100644 index 0000000..35a3ae4 --- /dev/null +++ b/crates/rpc-client/src/lib.rs @@ -0,0 +1,129 @@ +use anyhow::Result; +use domain::TransactionEvent; +use serde::Serialize; + +#[derive(Clone)] +pub struct AppConfig { + pub environment: Environment, +} + +#[derive(Clone, Copy)] +pub enum Environment { + Staging, + Production, +} + +impl AppConfig { + pub fn from_env() -> Self { + let env = std::env::var("APP_ENV").unwrap_or_else(|_| "staging".to_string()); + let environment = match env.to_lowercase().as_str() { + "production" | "prod" => Environment::Production, + _ => Environment::Staging, + }; + + Self { environment } + } + + pub fn backend_url(&self) -> String { + match self.environment { + Environment::Staging => std::env::var("BACKEND_STAGING_URL") + .unwrap_or_else(|_| "https://staging.ourpocket.com".to_string()), + Environment::Production => std::env::var("BACKEND_PROD_URL") + .unwrap_or_else(|_| "https://api.ourpocket.com".to_string()), + } + } +} + +#[async_trait::async_trait] +pub trait BackendClient { + async fn send_transaction(&self, event: TransactionEvent) -> Result<()>; +} + +#[derive(Clone)] +pub struct HttpBackendClient { + http_client: reqwest::Client, + config: AppConfig, +} + +impl HttpBackendClient { + pub fn new(config: AppConfig) -> Self { + Self { + http_client: reqwest::Client::new(), + config, + } + } +} + +#[derive(Serialize)] +struct TransactionRequestDto { + transaction_ref: String, + user_id: String, + application_id: String, + status: String, + amount: f64, + category: String, + metadata: serde_json::Value, +} + +#[async_trait::async_trait] +impl BackendClient for HttpBackendClient { + async fn send_transaction(&self, event: TransactionEvent) -> Result<()> { + let url = format!("{}/transactions/webhook", self.config.backend_url()); + + let payload = TransactionRequestDto { + transaction_ref: event.transaction_ref, + user_id: event.user_id, + application_id: event.application_id, + status: event.status, + amount: event.amount, + category: event.category, + metadata: event.metadata, + }; + + self.http_client.post(url).json(&payload).send().await?; + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn app_config_selects_environment_from_env() { + unsafe { std::env::set_var("APP_ENV", "staging") }; + let cfg = AppConfig::from_env(); + assert!(matches!(cfg.environment, Environment::Staging)); + + unsafe { std::env::set_var("APP_ENV", "production") }; + let cfg = AppConfig::from_env(); + assert!(matches!(cfg.environment, Environment::Production)); + } + + #[test] + fn backend_url_reads_from_env_with_fallbacks() { + unsafe { + std::env::remove_var("BACKEND_STAGING_URL"); + std::env::remove_var("BACKEND_PROD_URL"); + } + + let staging = AppConfig { + environment: Environment::Staging, + }; + assert!(staging.backend_url().contains("staging.ourpocket.com")); + + let prod = AppConfig { + environment: Environment::Production, + }; + assert!(prod.backend_url().contains("api.ourpocket.com")); + + unsafe { + std::env::set_var("BACKEND_STAGING_URL", "https://example-staging"); + std::env::set_var("BACKEND_PROD_URL", "https://example-prod"); + } + + assert_eq!(staging.backend_url(), "https://example-staging".to_string()); + assert_eq!(prod.backend_url(), "https://example-prod".to_string()); + } +} diff --git a/crates/webhook-server/Cargo.toml b/crates/webhook-server/Cargo.toml new file mode 100644 index 0000000..871e8b0 --- /dev/null +++ b/crates/webhook-server/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "webhook-server" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1" +axum = { version = "0.7", features = ["macros"] } +tokio = { version = "1", features = ["full"] } +serde_json = "1" +domain = { path = "../domain" } +queue = { path = "../queue" } +tower = "0.5" diff --git a/crates/webhook-server/src/main.rs b/crates/webhook-server/src/main.rs new file mode 100644 index 0000000..0932817 --- /dev/null +++ b/crates/webhook-server/src/main.rs @@ -0,0 +1,92 @@ +use axum::{ + Router, + extract::State, + http::StatusCode, + routing::{get, post}, +}; +use domain::normalize_payload; +use queue::{EventQueue, InMemoryQueue}; + +#[derive(Clone)] +struct AppState { + queue: Q, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let queue = InMemoryQueue::new(1024); + let state = AppState { queue }; + + let app = Router::new() + .route("/health", get(health_handler)) + .route("/webhook", post(webhook_handler::)) + .with_state(state); + + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?; + println!("listening on {}", listener.local_addr()?); + axum::serve(listener, app).await?; + + Ok(()) +} + +async fn health_handler() -> StatusCode { + StatusCode::OK +} + +async fn webhook_handler( + State(state): State>, + body: String, +) -> Result +where + Q: EventQueue + Clone + 'static, +{ + let event = normalize_payload(&body).map_err(|_| StatusCode::BAD_REQUEST)?; + + state + .queue + .publish(event) + .await + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + + Ok(StatusCode::OK) +} + +#[cfg(test)] +mod tests { + use super::*; + use axum::{body::Body, http::Request}; + use queue::InMemoryQueue; + use tower::ServiceExt; + + #[tokio::test] + async fn webhook_handler_returns_ok_for_valid_payload() { + let queue = InMemoryQueue::new(16); + let state = AppState { queue }; + + let app = Router::new() + .route("/webhook", post(webhook_handler::)) + .with_state(state); + + let body = r#" + { + "transactionRef": "abc123", + "userId": "user1", + "applicationId": "app1", + "status": "SUCCESS", + "amount": 100.5, + "category": "PAYMENT" + } + "#; + + let request = Request::builder() + .method("POST") + .uri("/webhook") + .header("content-type", "application/json") + .body(Body::from(body)) + .unwrap(); + + let response = app.oneshot(request).await.unwrap(); + + assert_eq!(response.status(), StatusCode::OK); + } +} diff --git a/crates/worker/Cargo.toml b/crates/worker/Cargo.toml new file mode 100644 index 0000000..ec8c912 --- /dev/null +++ b/crates/worker/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "worker" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1" +tokio = { version = "1", features = ["full"] } +domain = { path = "../domain" } +queue = { path = "../queue" } +rpc-client = { path = "../rpc-client" } +dotenvy = "0.15" +async-trait = "0.1" +serde_json = "1" diff --git a/crates/worker/src/main.rs b/crates/worker/src/main.rs new file mode 100644 index 0000000..92f703a --- /dev/null +++ b/crates/worker/src/main.rs @@ -0,0 +1,98 @@ +use anyhow::Result; +use dotenvy::dotenv; +use queue::{EventQueueConsumer, InMemoryQueue}; +use rpc_client::{AppConfig, BackendClient, HttpBackendClient}; + +#[tokio::main] +async fn main() -> Result<()> { + dotenv().ok(); + + // In a real deployment, this would connect to an external queue like SQS/Kafka/NATS. + // For now, this uses an in-memory queue instance as a placeholder. + let queue = InMemoryQueue::new(1024); + + let config = AppConfig::from_env(); + let backend_client = HttpBackendClient::new(config); + + worker_loop(queue, backend_client).await +} + +async fn worker_loop(queue: Q, backend_client: C) -> Result<()> +where + Q: EventQueueConsumer, + C: BackendClient, +{ + loop { + let event = queue.consume().await?; + backend_client.send_transaction(event).await?; + } +} + +#[cfg(test)] +mod tests { + use super::*; + use async_trait::async_trait; + use domain::TransactionEvent; + use std::sync::Arc; + use tokio::sync::Mutex; + + struct MockQueue { + events: Arc>>, + } + + #[async_trait] + impl EventQueueConsumer for MockQueue { + async fn consume(&self) -> Result { + let mut guard = self.events.lock().await; + guard + .pop() + .ok_or_else(|| anyhow::Error::msg("no events left")) + } + } + + struct MockBackend { + calls: Arc>>, + } + + #[async_trait] + impl BackendClient for MockBackend { + async fn send_transaction(&self, event: TransactionEvent) -> Result<()> { + let mut guard = self.calls.lock().await; + guard.push(event); + Ok(()) + } + } + + #[tokio::test] + async fn worker_loop_processes_events_until_error() { + let events = Arc::new(Mutex::new(vec![TransactionEvent { + transaction_ref: "ref-1".to_string(), + user_id: "user-1".to_string(), + application_id: "app".to_string(), + status: "SUCCESS".to_string(), + amount: 1.0, + category: "TEST".to_string(), + metadata: serde_json::json!({}), + }])); + + let calls = Arc::new(Mutex::new(Vec::new())); + + let queue = MockQueue { + events: Arc::clone(&events), + }; + let backend = MockBackend { + calls: Arc::clone(&calls), + }; + + let result = tokio::time::timeout( + std::time::Duration::from_millis(50), + worker_loop(queue, backend), + ) + .await; + + assert!(result.is_err() || result.unwrap().is_err()); + + let recorded = calls.lock().await; + assert_eq!(recorded.len(), 1); + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0da812c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +services: + webhook-server: + build: + context: . + dockerfile: Dockerfile + args: + BIN_NAME: webhook-server + ports: + - "3000:3000" + env_file: + - .env + + worker: + build: + context: . + dockerfile: Dockerfile + args: + BIN_NAME: worker + env_file: + - .env + depends_on: + - webhook-server diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100644 index 0000000..d108207 --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +if ! command -v cargo-llvm-cov >/dev/null 2>&1; then + echo "cargo-llvm-cov is not installed. Install with: cargo install cargo-llvm-cov" + exit 1 +fi +cargo llvm-cov --workspace --all-features --html + diff --git a/scripts/start-all.sh b/scripts/start-all.sh new file mode 100644 index 0000000..5b8ca30 --- /dev/null +++ b/scripts/start-all.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +cargo run -p webhook-server & +SERVER_PID=$! +cargo run -p worker & +WORKER_PID=$! +wait "$SERVER_PID" "$WORKER_PID" + diff --git a/scripts/start-webhook-server.sh b/scripts/start-webhook-server.sh new file mode 100644 index 0000000..d32e6e9 --- /dev/null +++ b/scripts/start-webhook-server.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +cargo run -p webhook-server + diff --git a/scripts/start-worker.sh b/scripts/start-worker.sh new file mode 100644 index 0000000..a59f91d --- /dev/null +++ b/scripts/start-worker.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +cargo run -p worker + diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000..3cf2834 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "$0")/.." +cargo test --workspace + diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index b93cf3f..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} From b366ddc962ee0fb4e03f958bf66cf4c2d875ff5e Mon Sep 17 00:00:00 2001 From: Melody Leonard Date: Sat, 21 Feb 2026 22:08:28 -0500 Subject: [PATCH 2/5] updated queue and added provider specific webhook normlizers --- .env.example | 3 +- .gitignore | 1 + Cargo.lock | 80 ++++++++++++++++++++-- crates/domain/src/flutterwave.rs | 86 ++++++++++++++++++++++++ crates/domain/src/lib.rs | 16 ++++- crates/domain/src/paystack.rs | 88 +++++++++++++++++++++++++ crates/queue/Cargo.toml | 1 + crates/queue/src/lib.rs | 106 ++++++++++++++++++++++++++++++ crates/webhook-server/src/main.rs | 36 ++++++---- crates/worker/src/main.rs | 11 ++-- docker-compose.yml | 6 ++ 11 files changed, 412 insertions(+), 22 deletions(-) create mode 100644 crates/domain/src/flutterwave.rs create mode 100644 crates/domain/src/paystack.rs diff --git a/.env.example b/.env.example index fb08ffb..1dcb842 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ APP_ENV=staging BACKEND_STAGING_URL=https://staging.ourpocket.com BACKEND_PROD_URL=https://api.ourpocket.com - +REDIS_URL=redis://redis:6379 +REDIS_QUEUE_KEY=ourpocket:transactions diff --git a/.gitignore b/.gitignore index ea8c4bf..0b745e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.env \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 879f246..562d461 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,6 +138,20 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -204,6 +218,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + [[package]] name = "futures-task" version = "0.3.32" @@ -217,6 +237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" dependencies = [ "futures-core", + "futures-sink", "futures-task", "pin-project-lite", "slab", @@ -350,7 +371,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2", + "socket2 0.6.2", "tokio", "tower-service", "tracing", @@ -633,6 +654,7 @@ dependencies = [ "anyhow", "async-trait", "domain", + "redis", "serde_json", "tokio", ] @@ -650,7 +672,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls", - "socket2", + "socket2 0.6.2", "thiserror", "tokio", "tracing", @@ -687,7 +709,7 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2", + "socket2 0.6.2", "tracing", "windows-sys 0.60.2", ] @@ -736,6 +758,27 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "redis" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" +dependencies = [ + "async-trait", + "bytes", + "combine", + "futures-util", + "itoa", + "percent-encoding", + "pin-project-lite", + "ryu", + "sha1_smol", + "socket2 0.5.10", + "tokio", + "tokio-util", + "url", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -934,6 +977,12 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + [[package]] name = "shlex" version = "1.3.0" @@ -962,6 +1011,16 @@ version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "socket2" version = "0.6.2" @@ -1072,7 +1131,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.6.2", "tokio-macros", "windows-sys 0.61.2", ] @@ -1098,6 +1157,19 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "tower" version = "0.5.3" diff --git a/crates/domain/src/flutterwave.rs b/crates/domain/src/flutterwave.rs new file mode 100644 index 0000000..8b0acd2 --- /dev/null +++ b/crates/domain/src/flutterwave.rs @@ -0,0 +1,86 @@ +use anyhow::Error; +use serde_json::Value; + +use crate::TransactionEvent; + +pub fn normalize_flutterwave_payload(raw: &str) -> Result { + let json: Value = serde_json::from_str(raw)?; + + let data = json.get("data").unwrap_or(&json); + + let transaction_ref = data["tx_ref"] + .as_str() + .or_else(|| data["txRef"].as_str()) + .unwrap_or("") + .to_string(); + + let user_id = data["customer"]["id"] + .as_str() + .or_else(|| data["customer"]["email"].as_str()) + .unwrap_or("") + .to_string(); + + let application_id = data["app_id"] + .as_str() + .or_else(|| data["meta"]["application_id"].as_str()) + .unwrap_or("flutterwave") + .to_string(); + + let status = data["status"].as_str().unwrap_or("").to_string(); + + let amount = data["amount"] + .as_f64() + .or_else(|| data["amount"].as_i64().map(|v| v as f64)) + .unwrap_or(0.0); + + let category = data["payment_type"] + .as_str() + .unwrap_or("FLUTTERWAVE") + .to_string(); + + Ok(TransactionEvent { + transaction_ref, + user_id, + application_id, + status, + amount, + category, + metadata: json, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn normalize_flutterwave_basic_payload() { + let raw = r#" + { + "data": { + "tx_ref": "flw-123", + "status": "successful", + "amount": 5000, + "payment_type": "card", + "customer": { + "id": "cust-1", + "email": "test@example.com" + }, + "meta": { + "application_id": "ourpocket-app" + } + } + } + "#; + + let event = normalize_flutterwave_payload(raw).expect("normalize_flutterwave_payload should succeed"); + + assert_eq!(event.transaction_ref, "flw-123"); + assert_eq!(event.user_id, "cust-1"); + assert_eq!(event.application_id, "ourpocket-app"); + assert_eq!(event.status, "successful"); + assert_eq!(event.amount, 5000.0); + assert_eq!(event.category, "card"); + } +} + diff --git a/crates/domain/src/lib.rs b/crates/domain/src/lib.rs index 11d412a..0f674d0 100644 --- a/crates/domain/src/lib.rs +++ b/crates/domain/src/lib.rs @@ -1,4 +1,18 @@ +mod flutterwave; +mod paystack; mod transaction; -pub use transaction::{normalize_payload, TransactionEvent}; +pub use flutterwave::normalize_flutterwave_payload; +pub use paystack::normalize_paystack_payload; +pub use transaction::{TransactionEvent, normalize_payload}; +pub fn normalize_webhook_payload(raw: &str) -> Result { + let json: serde_json::Value = serde_json::from_str(raw)?; + let provider = json["provider"].as_str().unwrap_or("").to_lowercase(); + + match provider.as_str() { + "flutterwave" => normalize_flutterwave_payload(raw), + "paystack" => normalize_paystack_payload(raw), + _ => Err(anyhow::Error::msg("unsupported provider")), + } +} diff --git a/crates/domain/src/paystack.rs b/crates/domain/src/paystack.rs new file mode 100644 index 0000000..1a4d51d --- /dev/null +++ b/crates/domain/src/paystack.rs @@ -0,0 +1,88 @@ +use anyhow::Error; +use serde_json::Value; + +use crate::TransactionEvent; + +pub fn normalize_paystack_payload(raw: &str) -> Result { + let json: Value = serde_json::from_str(raw)?; + + let data = json.get("data").unwrap_or(&json); + + let transaction_ref = data["reference"] + .as_str() + .or_else(|| data["data"]["reference"].as_str()) + .unwrap_or("") + .to_string(); + + let user_id = data["customer"]["id"] + .as_str() + .or_else(|| data["customer"]["email"].as_str()) + .unwrap_or("") + .to_string(); + + let application_id = data["meta"]["application_id"] + .as_str() + .or_else(|| data["channel"].as_str()) + .unwrap_or("paystack") + .to_string(); + + let status = data["status"].as_str().unwrap_or("").to_string(); + + let amount = data["amount"] + .as_f64() + .or_else(|| data["amount"].as_i64().map(|v| v as f64)) + .unwrap_or(0.0); + + let category = data["gateway_response"] + .as_str() + .unwrap_or("PAYSTACK") + .to_string(); + + Ok(TransactionEvent { + transaction_ref, + user_id, + application_id, + status, + amount, + category, + metadata: json, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn normalize_paystack_basic_payload() { + let raw = r#" + { + "event": "charge.success", + "data": { + "reference": "psk-123", + "status": "success", + "amount": 250000, + "channel": "card", + "gateway_response": "Approved", + "customer": { + "id": "cust-psk-1", + "email": "user@example.com" + }, + "meta": { + "application_id": "ourpocket-app" + } + } + } + "#; + + let event = + normalize_paystack_payload(raw).expect("normalize_paystack_payload should succeed"); + + assert_eq!(event.transaction_ref, "psk-123"); + assert_eq!(event.user_id, "cust-psk-1"); + assert_eq!(event.application_id, "ourpocket-app"); + assert_eq!(event.status, "success"); + assert_eq!(event.amount, 250000.0); + assert_eq!(event.category, "Approved"); + } +} diff --git a/crates/queue/Cargo.toml b/crates/queue/Cargo.toml index ae87d74..421cc86 100644 --- a/crates/queue/Cargo.toml +++ b/crates/queue/Cargo.toml @@ -9,3 +9,4 @@ async-trait = "0.1" domain = { path = "../domain" } tokio = { version = "1", features = ["sync"] } serde_json = "1" +redis = { version = "0.25", features = ["aio", "tokio-comp"] } diff --git a/crates/queue/src/lib.rs b/crates/queue/src/lib.rs index e6000b9..e6cd70a 100644 --- a/crates/queue/src/lib.rs +++ b/crates/queue/src/lib.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use anyhow::Error; use async_trait::async_trait; use domain::TransactionEvent; +use redis::AsyncCommands; use tokio::sync::mpsc; #[async_trait] @@ -31,6 +32,23 @@ impl InMemoryQueue { } } +#[derive(Clone)] +pub struct RedisQueue { + client: redis::Client, + queue_key: String, +} + +impl RedisQueue { + pub fn new(redis_url: &str, queue_key: impl Into) -> Result { + let client = redis::Client::open(redis_url).map_err(|err| Error::msg(err.to_string()))?; + + Ok(Self { + client, + queue_key: queue_key.into(), + }) + } +} + #[async_trait] impl EventQueue for InMemoryQueue { async fn publish(&self, event: TransactionEvent) -> Result<(), Error> { @@ -51,6 +69,48 @@ impl EventQueueConsumer for InMemoryQueue { } } +#[async_trait] +impl EventQueue for RedisQueue { + async fn publish(&self, event: TransactionEvent) -> Result<(), Error> { + let mut conn = self + .client + .get_multiplexed_async_connection() + .await + .map_err(|err| Error::msg(err.to_string()))?; + + let payload = serde_json::to_string(&event).map_err(|err| Error::msg(err.to_string()))?; + + let _: () = conn + .lpush(&self.queue_key, payload) + .await + .map_err(|err| Error::msg(err.to_string()))?; + + Ok(()) + } +} + +#[async_trait] +impl EventQueueConsumer for RedisQueue { + async fn consume(&self) -> Result { + let mut conn = self + .client + .get_multiplexed_async_connection() + .await + .map_err(|err| Error::msg(err.to_string()))?; + + let (_key, payload): (String, String) = redis::cmd("BRPOP") + .arg(&self.queue_key) + .arg(0) + .query_async(&mut conn) + .await + .map_err(|err| Error::msg(err.to_string()))?; + + let event = serde_json::from_str(&payload).map_err(|err| Error::msg(err.to_string()))?; + + Ok(event) + } +} + #[cfg(test)] mod tests { use super::*; @@ -94,4 +154,50 @@ mod tests { let result = queue.consume().await; assert!(result.is_err()); } + + #[tokio::test] + async fn redis_queue_persists_items_across_instances() { + let redis_url = + std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string()); + let queue_key = "ourpocket:test:transactions_persist"; + + let client = match redis::Client::open(redis_url.clone()) { + Ok(c) => c, + Err(_) => return, + }; + + let mut conn = match client.get_multiplexed_async_connection().await { + Ok(c) => c, + Err(_) => return, + }; + + let _ = redis::cmd("DEL") + .arg(queue_key) + .query_async::<_, ()>(&mut conn) + .await; + + let queue1 = match RedisQueue::new(&redis_url, queue_key) { + Ok(q) => q, + Err(_) => return, + }; + + let event = build_event("redis-user-1"); + if queue1.publish(event.clone()).await.is_err() { + return; + } + + drop(queue1); + + let queue2 = match RedisQueue::new(&redis_url, queue_key) { + Ok(q) => q, + Err(_) => return, + }; + + let consumed = match queue2.consume().await { + Ok(ev) => ev, + Err(_) => return, + }; + + assert_eq!(consumed, event); + } } diff --git a/crates/webhook-server/src/main.rs b/crates/webhook-server/src/main.rs index 0932817..8a01bc5 100644 --- a/crates/webhook-server/src/main.rs +++ b/crates/webhook-server/src/main.rs @@ -4,8 +4,8 @@ use axum::{ http::StatusCode, routing::{get, post}, }; -use domain::normalize_payload; -use queue::{EventQueue, InMemoryQueue}; +use domain::normalize_webhook_payload; +use queue::{EventQueue, RedisQueue}; #[derive(Clone)] struct AppState { @@ -14,12 +14,17 @@ struct AppState { #[tokio::main] async fn main() -> anyhow::Result<()> { - let queue = InMemoryQueue::new(1024); + let redis_url = + std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string()); + let queue_key = + std::env::var("REDIS_QUEUE_KEY").unwrap_or_else(|_| "ourpocket:transactions".to_string()); + + let queue = RedisQueue::new(&redis_url, queue_key)?; let state = AppState { queue }; let app = Router::new() .route("/health", get(health_handler)) - .route("/webhook", post(webhook_handler::)) + .route("/webhook", post(webhook_handler::)) .with_state(state); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?; @@ -40,7 +45,7 @@ async fn webhook_handler( where Q: EventQueue + Clone + 'static, { - let event = normalize_payload(&body).map_err(|_| StatusCode::BAD_REQUEST)?; + let event = normalize_webhook_payload(&body).map_err(|_| StatusCode::BAD_REQUEST)?; state .queue @@ -59,7 +64,7 @@ mod tests { use tower::ServiceExt; #[tokio::test] - async fn webhook_handler_returns_ok_for_valid_payload() { + async fn webhook_handler_returns_ok_for_flutterwave_payload() { let queue = InMemoryQueue::new(16); let state = AppState { queue }; @@ -69,12 +74,19 @@ mod tests { let body = r#" { - "transactionRef": "abc123", - "userId": "user1", - "applicationId": "app1", - "status": "SUCCESS", - "amount": 100.5, - "category": "PAYMENT" + "provider": "flutterwave", + "data": { + "tx_ref": "abc123", + "status": "SUCCESS", + "amount": 100.5, + "payment_type": "PAYMENT", + "customer": { + "id": "user1" + }, + "meta": { + "application_id": "app1" + } + } } "#; diff --git a/crates/worker/src/main.rs b/crates/worker/src/main.rs index 92f703a..1a55b0a 100644 --- a/crates/worker/src/main.rs +++ b/crates/worker/src/main.rs @@ -1,15 +1,18 @@ use anyhow::Result; use dotenvy::dotenv; -use queue::{EventQueueConsumer, InMemoryQueue}; +use queue::{EventQueueConsumer, RedisQueue}; use rpc_client::{AppConfig, BackendClient, HttpBackendClient}; #[tokio::main] async fn main() -> Result<()> { dotenv().ok(); - // In a real deployment, this would connect to an external queue like SQS/Kafka/NATS. - // For now, this uses an in-memory queue instance as a placeholder. - let queue = InMemoryQueue::new(1024); + let redis_url = + std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string()); + let queue_key = + std::env::var("REDIS_QUEUE_KEY").unwrap_or_else(|_| "ourpocket:transactions".to_string()); + + let queue = RedisQueue::new(&redis_url, queue_key)?; let config = AppConfig::from_env(); let backend_client = HttpBackendClient::new(config); diff --git a/docker-compose.yml b/docker-compose.yml index 0da812c..63c2049 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,3 +20,9 @@ services: - .env depends_on: - webhook-server + - redis + + redis: + image: redis:7-alpine + ports: + - "6379:6379" From d918c129c4034a0aca88128a75795ca191d37e6e Mon Sep 17 00:00:00 2001 From: Melody Leonard Date: Sat, 21 Feb 2026 22:19:37 -0500 Subject: [PATCH 3/5] added pre-commit hook --- .githooks/pre-commit | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..0701c3d --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" +cd "$REPO_ROOT" + +echo "[pre-commit] Running cargo fmt..." +cargo fmt --all + +echo "[pre-commit] Running tests..." +if [ -x "./scripts/test.sh" ]; then + ./scripts/test.sh +else + cargo test --workspace +fi + +echo "[pre-commit] All checks passed." + From 9084bb4cc76958ceeedf30947cd094339312a10c Mon Sep 17 00:00:00 2001 From: Melody Leonard Date: Sat, 21 Feb 2026 22:21:22 -0500 Subject: [PATCH 4/5] test pre-commit --- .githooks/pre-commit | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit old mode 100644 new mode 100755 From bba1309281993c62e0527d3f844ec97dbb211d5a Mon Sep 17 00:00:00 2001 From: Melody Leonard Date: Sat, 21 Feb 2026 22:23:53 -0500 Subject: [PATCH 5/5] some change --- .githooks/pre-commit | 4 +++- crates/domain/src/flutterwave.rs | 4 ++-- crates/domain/src/transaction.rs | 11 ++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 0701c3d..28305dc 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -14,5 +14,7 @@ else cargo test --workspace fi -echo "[pre-commit] All checks passed." +echo "[pre-commit] Staging formatted files..." +git add -u +echo "[pre-commit] All checks passed." diff --git a/crates/domain/src/flutterwave.rs b/crates/domain/src/flutterwave.rs index 8b0acd2..749e117 100644 --- a/crates/domain/src/flutterwave.rs +++ b/crates/domain/src/flutterwave.rs @@ -73,7 +73,8 @@ mod tests { } "#; - let event = normalize_flutterwave_payload(raw).expect("normalize_flutterwave_payload should succeed"); + let event = normalize_flutterwave_payload(raw) + .expect("normalize_flutterwave_payload should succeed"); assert_eq!(event.transaction_ref, "flw-123"); assert_eq!(event.user_id, "cust-1"); @@ -83,4 +84,3 @@ mod tests { assert_eq!(event.category, "card"); } } - diff --git a/crates/domain/src/transaction.rs b/crates/domain/src/transaction.rs index 15037ac..793303a 100644 --- a/crates/domain/src/transaction.rs +++ b/crates/domain/src/transaction.rs @@ -15,15 +15,9 @@ pub fn normalize_payload(raw: &str) -> Result { let json: serde_json::Value = serde_json::from_str(raw)?; Ok(TransactionEvent { - transaction_ref: json["transactionRef"] - .as_str() - .unwrap_or("") - .to_string(), + transaction_ref: json["transactionRef"].as_str().unwrap_or("").to_string(), user_id: json["userId"].as_str().unwrap_or("").to_string(), - application_id: json["applicationId"] - .as_str() - .unwrap_or("") - .to_string(), + application_id: json["applicationId"].as_str().unwrap_or("").to_string(), status: json["status"].as_str().unwrap_or("").to_string(), amount: json["amount"].as_f64().unwrap_or(0.0), category: json["category"].as_str().unwrap_or("").to_string(), @@ -64,4 +58,3 @@ mod tests { ); } } -