Skip to main content

cratefield_core/
lib.rs

1//! `cratefield-core` is the runtime-agnostic kernel of the Factory Zero harness:
2//! the [`Module`] contract, the [`Harness`] builder, port traits, RFC 9457
3//! problem+json errors, the request [`Scope`], an in-process [`EventBus`] and
4//! a [`TemplateRegistry`] (ADR 0001, 0002, 0007).
5//!
6//! Core depends only on `http`, `axum` (default features off), `serde`,
7//! `tracing`, `sea-query` and pure-Rust crypto. It must never depend on
8//! `worker`, `wasm-bindgen`, `tokio`, `reqwest`, `sqlx` or `rusqlite`, and
9//! never touches `std::fs` or `std::net` — CI enforces this with a
10//! `cargo tree` check and the wasm build of `examples/venture`.
11
12#![doc = include_str!("../README.md")]
13#![forbid(unsafe_code)]
14
15mod admin;
16mod config;
17mod cooldown;
18mod csv;
19mod email;
20mod events;
21mod harness;
22mod http;
23mod idempotency;
24mod lint;
25mod logging;
26mod module;
27mod origin;
28mod outbox;
29mod personal_data;
30mod ports;
31mod problem;
32mod problems;
33mod rate_limit;
34mod route_policy;
35mod scope;
36mod sidecar;
37mod signer;
38mod surface;
39mod template;
40mod tenant;
41mod tenant_conn;
42mod venture;
43
44pub use admin::{bearer_token, constant_time_eq, require_admin};
45pub use config::{Config, ConfigError, EmptyConfig, HarnessConfig, MapConfig, ModuleConfig};
46pub use cooldown::SendCooldown;
47pub use csv::{FORMULA_PREFIXES, MAX_EXPORT_ROWS, escape as csv_escape, row as csv_row};
48pub use email::{
49    MAX_EMAIL_BYTES, MAX_LOCAL_BYTES, invalid_email_problem, is_valid,
50    normalize as normalize_email, validation_error,
51};
52pub use events::{AnyError, EventBus, EventHandler, EventName};
53pub use harness::{Harness, HarnessBuilder, Runtime};
54pub use http::{Form, Json, MAX_BODY_BYTES, X_REQUEST_ID, rate_limited, request_id_is_valid};
55pub use idempotency::Inbox;
56pub use lint::{card_data_hit, created_tables, lint_card_data, lint_portable_sql};
57pub use logging::{
58    RedactingVisitor, is_email_field, is_secret_field, redacted_value, scrub_request_url,
59    scrub_text, set_error_forwarder, set_log_pseudonym_key, subject_hash,
60};
61pub use module::{
62    BoxFuture, HARNESS_API, Migrations, Module, ModuleContext, SqlMigration, assert_migration_set,
63    harness_api_mismatch, is_idempotent_sql, migration_checksum, migration_edited,
64    migration_missing_guard,
65};
66pub use origin::{OriginError, origin_of};
67pub use outbox::{Outbox, OutboxRecord};
68pub use personal_data::{
69    CatalogEntry, DataKind, Disposition, PersonalDataCatalog, PersonalDataSet, SubjectVia,
70    is_plain_identifier, migration_tables, undeclared_tables, unlisted_tables,
71};
72pub use ports::{
73    Blob, BlobError, BlobObject, BoundedHttpClient, Captcha, CaptchaBinding, CaptchaError, Charge,
74    CheckoutRequest, CheckoutSession, Clock, ConnectAccountLink, ConnectAccountLinkRequest,
75    DEFAULT_RESPONSE_TIMEOUT, Database, DbError, Decision, Defer, DispatchError, Dispatcher,
76    HttpClient, HttpError, HttpPolicy, IdGen, KeyValue, Kid, KvError, LineItem, LocKeys,
77    MAX_BLOB_BYTES, MAX_CONCURRENT_REQUESTS, MAX_KID_NAME, MAX_RESPONSE_BYTES,
78    MAX_RESPONSE_TIMEOUT, MailError, Mailer, Member, Message, Money, NoopDefer, Notification,
79    Payload, Payments, PaymentsError, Platform, Port, Ports, Priority, Push, PushError,
80    PushOutcome, RateLimitError, RateLimiter, Realtime, RealtimeError, Recipient, Refund,
81    RefundRequest, RoomContext, RoomHandler, RoutingPush, Row, Rows, ScopedBlob, SendOutcome,
82    SignatureError, Signer, Statement, SubscriptionCheckoutRequest, SystemClock, TransferCharge,
83    TryFromValue, UlidIdGen, Verdict, WebhookEvent, check_blob_size, declared_content_length,
84    retry_after, timeout, ttl_secs,
85};
86pub use problem::Problem;
87pub use problems::{ProblemDef, SLUGS, registry as problem_registry};
88pub use rate_limit::{RateLimit, RateLimitFailure, check_rate_limit, client_ip, rate_limit_keys};
89pub use route_policy::{
90    ALLOW_UNPROTECTED_WRITES, RoutePolicy, WriteGuards, captcha_effective, deployed_env,
91    env_disagreement, payments_effective, production_readiness, signer_effective,
92    unprotected_writes_override, verify_human_form,
93};
94pub use scope::Scope;
95pub use sidecar::{
96    GATEWAY_ADMIN_PURPOSE, GATEWAY_PURPOSE, GATEWAY_TOKEN_TTL_SECS, HARNESS_ONE_WORKER,
97    HARNESS_SIDECARS, SIDECAR_GATEWAY_SECRET, SIDECAR_REQUIRE_GATEWAY, SidecarMount, SidecarMounts,
98    X_HARNESS_API, X_HARNESS_GATEWAY, X_HARNESS_MODULE,
99};
100pub use signer::{
101    CONFIRM_TOKEN_MAX_TTL_SECS, DEFAULT_TOKEN_MAX_TTL_SECS, HmacSigner, KeyRing, KeyState,
102    MIN_SECRET_BYTES, RingKey, STATUS_TOKEN_MAX_TTL_SECS, SignerError, TokenPolicy,
103    UNSUBSCRIBE_ACTION,
104};
105pub use surface::{
106    Action, Audience, Column, HINT_KEYWORDS, MAX_SIDECAR_ACTIONS, MAX_SIDECAR_SURFACE_BYTES,
107    MAX_SIDECAR_VIEWS, ModuleSurface, Outcome, RenderedSurface, SURFACE_API, Surface,
108    SurfaceDocument, SurfaceSource, UiContext, UiMount, VentureSurface, View, hint_field,
109    schema_for,
110};
111pub use template::{Rendered, Template, TemplateError, TemplateRegistry};
112pub use tenant::{
113    IMPLICIT_TENANT, ImplicitTenant, Resolution, ResolveTenant, Tenant, TenantDatabases,
114    TenantDbError, TenantId, TenantRouting, TenantStatus,
115};
116pub use tenant_conn::TenantConn;
117pub use venture::{Brand, Venture, VentureEnv};