Skip to content

Rust SDK

flowcatalyst-sdk is the Rust member of the SDK family. It writes the same outbox rows as the Go, Java, TypeScript and PHP SDKs, the same event, dispatch-job and audit payloads and the same TSIDs, and verifies the same delivery signatures. It is stable Rust, edition 2024, MSRV 1.98 (the repository pins toolchain 1.98.1), Apache-2.0, with unsafe_code forbidden.

The crate lives at clients/rust-sdk in the platform repository. Cargo finds a package by name inside a git repository, so a git dependency needs no path:

[dependencies]
flowcatalyst-sdk = { git = "<platform repository URL>", rev = "<commit>" }
  • Pin a rev. There is no tag to pin. Use a commit you have read.
  • Your build needs read access to that repository (an SSH key or a token, as for any private git dependency). The platform repository is not guaranteed to stay publicly readable.
  • To avoid depending on repository access at build time, vendor the crate (cargo vendor) or copy clients/rust-sdk into your workspace as a path dependency.

Choose features to keep the dependency graph small:

flowcatalyst-sdk = { git = "...", rev = "...", default-features = false, features = ["outbox-postgres", "webhook"] }
Feature Default Brings
(always) tsid: time-sorted ids with typed prefixes
outbox yes CreateEventDto, DispatchJob, CreateAuditLogDto, CreatePush, OutboxManager, the canonical outbox_messages DDL
outbox-postgres PgOutboxDriver (sqlx)
outbox-mysql MySqlOutboxDriver (sqlx)
webhook yes WebhookVerifier, sign, MediationResponse, X-FlowCatalyst-Client parsing
client yes FlowCatalystClient (the platform HTTP API), ClientCredentials, and sync (definition sync)
push-tickets yes Push ticket keys and EdDSA tickets, and the push rules the application syncs
auth Access-token claims, JWKS (RS256) and HS256 validation, the OAuth authorization-code client

(The crate’s README omits push-tickets from its table; Cargo.toml is the authority.) Dependencies are deliberately few: serde, serde_json, thiserror and getrandom always; reqwest with rustls only and tokio (sync, time) for the client; sqlx only with a driver feature, with no TLS or runtime choice of its own, so your sqlx dependency decides.

Events are written to outbox_messages in your transaction, and a relay sends them; see the transactional outbox. The Rust shape is “prepare the rows, then insert them on your own transaction”:

use flowcatalyst_sdk::outbox::{CreateEventDto, DispatchJob, OutboxManager, PgOutboxDriver};
let driver = PgOutboxDriver::new(pool.clone());
let outbox = OutboxManager::new(driver.clone(), "clt_0HZXEQ5Y8JY5Z")?; // the owning client's id
let event = CreateEventDto::new("shop:orders:order:placed", &order_placed)?
.message_group(format!("orders:order:{id}"))
.client_code("acme");
let job = DispatchJob::builder("shop:fulfilment:pick", "https://warehouse.example.com/hooks/pick")
.json_payload(&pick)?
.build()?;
let mut tx = pool.begin().await?;
// ... business writes on &mut *tx ...
driver.insert_in(&mut tx, &[outbox.prepare_event(&event)?, outbox.prepare_dispatch_job(&job)?]).await?;
tx.commit().await?;

examples/outbox-postgres.rs also writes an audit entry (CreateAuditLogDto::new(entity_type, entity_id, operation, principal_id)) and creates the table with init_postgres_schema.

  • OutboxManager::new returns an error for a blank client id. with_client_code(slug) sets the default client for pushes that name none.
  • prepare_event, prepare_dispatch_job, prepare_audit_log and prepare_push build rows without I/O. driver.insert_in(&mut tx, &rows) writes them on your transaction as one multi-row statement. create_event and the other create_* methods write through the driver on their own, which is not atomic with your data.
  • Events. The type must have four non-empty segments, and data must be a JSON object. A deduplicationId defaults to the outbox row id unless deduplication_id sets one, so a re-sent batch does not create a duplicate. Other setters: source, subject, correlation_id, causation_id, message_group, client_code, context, header.
  • Dispatch jobs. DispatchJob::builder(code, url)...build()? refuses what the platform would refuse terminally: the code shape, the target URL scheme, host and user info, id and column lengths, enums and metadata keys. Defaults: kind TASK, dataOnly false, payload {}, the id a 13-character TSID, and the numbers only when set and at least 1. There is no connection_id or idempotency_key: the platform now honours both, and the Go and Java SDKs write them, but this crate’s builder does not (its module note is stale). Use the Go or Java SDK where a job needs an idempotency key.
  • Audit entries require a principal id, and operation data is redacted with the shared vectors before it is written.
  • Push. CreatePush and prepare_push / create_push write PUSH rows; the Postgres driver notifies fc_outbox_push in the insert.
  • Tables. The DDL is the Java SDK’s migration files byte for byte (VARCHAR(26) id, TEXT payload, the relay’s partial indexes). init_postgres_schema and init_mysql_schema create the table when it is absent; use your own migrations in production. fcdev outbox reads a MySQL 8.0+ or MariaDB 10.6+ outbox as well as a PostgreSQL one (see which relay drains which database).
use flowcatalyst_sdk::client::{ClientCredentials, FlowCatalystClient};
let client = FlowCatalystClient::new("https://platform.example.com")
.with_token_source(ClientCredentials::new("https://platform.example.com", "svc-orders", secret));
let pools = client.dispatch_pools().list(&Default::default()).await?;
  • Tokens. with_token("...") for a static token, or ClientCredentials: the client_credentials grant with the credentials in the form body, cached until 60 seconds before expiry, fetched single-flight, and cleared and refetched once on a 401.
  • Retries. Exponential backoff. 408, 429 and a failure to connect are retried for every request. 502, 503, 504 and a transport failure after the request may have been sent (reset, end of stream, timeout) are retried only for a repeatable request: GET, HEAD, OPTIONS, PUT, DELETE and the few POSTs the SDK marks repeatable (the declarative syncs and the router’s read-only in-flight check). Any other request fails with ClientError::OutcomeUnknown and is not sent again, because the platform may have applied it; is_outcome_unknown() tests for it, and you should read the state before sending it again. A DELETE that answers 404 after such an unknown outcome succeeds. 500 and every other status are not retried. Defaults are changed with with_retry(attempts, base_delay) and with_timeout(d); with_router_url sets the router host and with_http_client swaps the reqwest::Client.
  • Errors. ClientError::Api { status, code, message, body } carries the platform’s {error, message} envelope; status(), is_not_found() and is_conflict() help. Every caller-supplied path segment is percent-encoded.
  • Resources. applications, audit_logs, clients, connections, ingestions, dispatch_pools, event_types, me, permissions, platform_config, principals, processes, openapi, docs, push, roles, router, scheduled_jobs, service_accounts and subscriptions. There are no field-worker resources.
  • The platform-config resource has reveal_secret, which returns a SecretValue that prints *** in Debug and Display (expose() reads it); it is audited and never cached. See configuration and secrets.
use flowcatalyst_sdk::sync::{DefinitionSet, DefinitionSynchronizer, EventTypeDefinition, RoleDefinition, SyncOptions};
let set = DefinitionSet::for_application("billing")
.add_role(RoleDefinition::make("billing:admin").with_permissions(vec!["billing:invoices:invoice:read".into()]))
.add_event_type(EventTypeDefinition::make("billing:invoices:invoice:created", "Invoice Created"));
let result = DefinitionSynchronizer::new(client).sync(&set, &SyncOptions::with_remove_unlisted()).await;
result.into_result()?; // any failed category becomes an error

examples/fc-sync.rs is a complete program. The categories run in this order: roles, event types, dispatch pools, connections, subscriptions, processes, scheduled jobs, principals, OpenAPI, docs, push. If the connections category fails, subscriptions are not sent. Each category is checked locally before its request and fails, naming the values, on duplicates, event-type codes that are not {app}:x:y:z, role permissions outside the application, subscription targets that are not absolute http(s) URLs (path targets resolve against with_subscription_target_base_url), crons that are not six-field seconds-first, and malformed docs slugs.

Behaviour that differs from the other SDKs:

  • Principal role names without an app: prefix are prefixed with the application by this crate. The other SDKs send the names as written, and the platform stores them verbatim.
  • Scheduled jobs are sent per client_id group.
use flowcatalyst_sdk::webhook::{WebhookVerifier, SIGNATURE_HEADER, TIMESTAMP_HEADER};
let verifier = WebhookVerifier::from_env()?; // FLOWCATALYST_SIGNING_SECRET
verifier.verify(&raw_body, headers.get(SIGNATURE_HEADER), headers.get(TIMESTAMP_HEADER))?;

The verifier fails closed on an empty secret, treats an empty header as missing, compares the hex signature ignoring case, accepts an ISO 8601 or a Unix-seconds timestamp, refuses a timestamp older than the tolerance (DEFAULT_TOLERANCE_SECS, 300; with_tolerance) or more than 60 seconds ahead, and can add a bearer-token gate (with_bearer_token, verify_with_authorization). Its errors (WebhookError::code()) use the same codes as the Java SDK. MediationResponse::ack(), defer(secs) and flush_group(...) build the answer to a delivery. parse_client_header reads X-FlowCatalyst-Client. See delivery and webhook signatures.

TicketMinter signs short-lived EdDSA tickets that let a browser listen to push topics, and its JWKS is what the application syncs with DefinitionSet::with_push. See push.

With the auth feature the crate validates RS256 access tokens by JWKS (an unknown kid triggers one refetch, an empty key set is an error) and HS256 tokens, and provides an OAuth authorization-code client with PKCE, refresh, revoke, introspect, userinfo and logout_url.

By design the crate has no use-case envelope, no cache, no locks, no scheduled-job runner and no web framework integration; the application framework owns those. It has no field-worker verifier or admin client. See the feature matrix.

From clients/rust-sdk: make ci runs cargo fmt --check, clippy -D warnings (with all and with no features), the tests, the Go conformance test and cargo deny. make test-db-up, make test-db and make test-db-down run the sqlx driver tests against throwaway Postgres and MySQL containers.

Wire compatibility is tested both ways. tests/fixtures/wire/*.json are golden payloads the SDK must produce byte for byte, and a Go test in the platform repository decodes the same files with the platform’s own types and checks the signature, TSID, DDL and redaction vectors against the Go and Java SDKs.