x402 gated http api#295
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a dev/test “mock facilitator” and wires the parser HTTP gateway with an x402 v2 payment-gated /visualsign/api/v2/parse endpoint, plus an end-to-end demo script and an integration test covering payment-required and paid flows.
Changes:
- Introduces
parser/mock-facilitatorAxum service (workspace member) with a Docker image. - Refactors
parser_gatewayinto a lib+bin layout, adds x402 config/env loading, and gates the new v2 parse route with x402 middleware. - Adds an end-to-end demo script and an integration test that boots mock facilitator + gRPC server + gateway.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/parser/mock-facilitator/src/main.rs | Mock facilitator binary entrypoint + graceful shutdown. |
| src/parser/mock-facilitator/src/lib.rs | Mock facilitator HTTP routes (/verify, /settle, /supported) + unit tests. |
| src/parser/mock-facilitator/Cargo.toml | New crate manifest/deps for mock facilitator. |
| src/parser/mock-facilitator/build.rs | Injects VERSION into build for runtime banner logging. |
| src/parser/gateway/src/x402_config.rs | New env/profile-based x402 configuration + price-tag building. |
| src/parser/gateway/src/turnkey.rs | Extracts Turnkey request/response envelope types + error helper. |
| src/parser/gateway/src/state.rs | Extracts shared gateway app state types. |
| src/parser/gateway/src/main.rs | Wires v1 open route + v2 x402-gated route and adds facilitator startup probe. |
| src/parser/gateway/src/lib.rs | New library entrypoint exporting handlers/state/config modules. |
| src/parser/gateway/src/handlers/parse.rs | Shared parse handler used by both v1 and v2 routes. |
| src/parser/gateway/src/handlers/mod.rs | Handler module declarations. |
| src/parser/gateway/src/handlers/health.rs | Health endpoint handler (gRPC health proxy). |
| src/parser/gateway/Cargo.toml | Updates dependencies (axum 0.8, x402 crates, reqwest, etc.) and adds lib target. |
| src/integration/tests/x402_gateway_test.rs | New end-to-end test booting three binaries and exercising v1/v2 behaviors. |
| src/integration/Cargo.toml | Adds dev-deps needed for new HTTP-based integration test. |
| src/Cargo.toml | Adds parser/mock-facilitator to workspace members. |
| src/Cargo.lock | Locks new dependencies (x402 crates, reqwest 0.13, etc.). |
| scripts/x402-demo.sh | Narrated demo script to run the full stack locally and walk through scenarios. |
| Makefile | Adds mock_facilitator image build outputs and non-OCI build target. |
| images/parser_gateway/Containerfile | Sets image ENV defaults for local x402 profile/facilitator URL. |
| images/mock_facilitator/Containerfile | New Docker build for mock facilitator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn parse_tags_json(json: &str) -> Result<Vec<PriceTagConfig>, ConfigError> { | ||
| let wire: Vec<PriceTagWire> = | ||
| serde_json::from_str(json).map_err(|e| ConfigError::JsonParse(e.to_string()))?; | ||
| wire.into_iter() | ||
| .map(|w| { | ||
| Ok(PriceTagConfig { | ||
| network: w.network, | ||
| asset: w.asset, | ||
| price_usd: Decimal::from_str(&w.price_usd).map_err(|e| { | ||
| ConfigError::Invalid { | ||
| var: "X402_PRICE_TAGS_JSON", | ||
| message: format!("priceUsd: {e}"), | ||
| } | ||
| })?, | ||
| pay_to: w.pay_to.into_pay_to()?, | ||
| scheme: w.scheme, | ||
| }) |
| chapter "Preflight" "Make sure we have everything we need before starting." | ||
|
|
||
| for tool in curl jq base64 cargo; do | ||
| if ! command -v "$tool" >/dev/null 2>&1; then | ||
| fail "missing tool: $tool" | ||
| fi | ||
| done | ||
| ok "curl, jq, base64, cargo all present" |
|
@copilot address the comments, rebase, and resolve conflicts |
Addressed the review comments in |
Adds the design for a new POST /visualsign/api/v2/parse route with x402-axum middleware, a mock_facilitator dev binary, and env+profile config (local/payai/custom) with multi-tag support. Existing Turnkey v1 endpoint and /health remain unprotected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Implemented a health-check handler in `health.rs` that proxies to the gRPC backend's health service, returning the service status. - Created a shared parse handler in `parse.rs` for processing requests from both v1 and v2 parse endpoints, with appropriate error handling and response formatting. - Introduced a new module `handlers` to organize the health and parse handlers. - Established application state management in `state.rs` to hold gRPC clients. - Added `turnkey.rs` for handling request/response envelopes specific to parse endpoints. - Configured x402 settings in `x402_config.rs` to load from environment variables, including profile management and price tag configurations. - Developed a mock facilitator service in `mock-facilitator` for testing purposes, including endpoints for verification and settlement. - Included tests for the new functionality to ensure reliability and correctness.
Agent-Logs-Url: https://github.com/anchorageoss/visualsign-parser/sessions/ea819765-afae-4e0f-a3c6-ebaa40e503ed Co-authored-by: andrestielau <115989486+andrestielau@users.noreply.github.com>
Agent-Logs-Url: https://github.com/anchorageoss/visualsign-parser/sessions/ea819765-afae-4e0f-a3c6-ebaa40e503ed Co-authored-by: andrestielau <115989486+andrestielau@users.noreply.github.com>
899cdbf to
35b6938
Compare
Screen.recording.2026-05-13.12.30.03.PM.webm
This pull request introduces a new mock facilitator service and a narrated demo script to support and showcase the x402 v2 payment-gated HTTP API in the parser_gateway. It adds Docker build support for the mock facilitator, updates environment configuration for local development, and enhances integration test dependencies.
Key changes include:
New mock facilitator service:
parser/mock-facilitatorcrate to the workspace and created a corresponding Docker build (images/mock_facilitator/Containerfile,src/Cargo.toml,Makefile). [1] [2] [3]images/parser_gateway/Containerfile).Demo and developer tooling:
scripts/x402-demo.sh, a narrated, end-to-end Bash script that spins up the mock facilitator, parser gRPC server, and gateway, demonstrating various payment and error scenarios with commentary. This script aids both development and onboarding.Integration test improvements:
reqwestandtokioas dev-dependencies to the integration test crate to support more advanced HTTP and async test scenarios (src/integration/Cargo.toml).