saola-kit 0.2.0

Saola core toolkit for Laravel for Rust (contexts, envelope protocol, i18n, masks, modules, Sanctum-compatible tokens)
Documentation

saola-kit

Core Saola toolkit for Laravel for Rust (laravel-rust), providing the Saola-specific conventions and contracts on top of Laravel's native routing, database, auth, and view primitives.

Features

Feature Default Description
context yes Multi-context host normalization (ContextHosts), cross-host RouteIndex::href(), and client_links()
envelope yes Saola { data, view?, auth? } JSON Envelope, PageResponse (saola_kit::envelope::render), ClientAuthProjection, and ClientShare
i18n yes Strict LanguageTree/LanguageJson, TextResolver (:name/:Name/:NAME), and scoped ClientCatalogs (X-Saola-Language)
masks yes Mask<T> projection trait and PiiMask helpers
module yes Ordered SaolaModule & ModuleRegistry
tokens no Laravel Sanctum-compatible personal_access_tokens store and SanctumGuard<U> (Authenticate::via)
repository no PageParams, PageResult, and CursorParams pagination helpers
smtp no SMTP delivery through Laravel mail, using STARTTLS or implicit TLS
view no SSR for compiled Saola templates: the full MiniJinja helper contract (text/trans/__, route/href, truthy, empty, index_of, count, sprintf, json_encode, auth_user, optional site_* via SsrSite) and PageResponse::ssr
permission no Route-level permission groups on the context router: ctx.module_with, ctx.require, ctx.enforce_with::<User>(), route.permission(..) (needs saola-permission)
full no Enables all library features above

Pass-through database driver features (database-postgres, database-mysql, database-sqlite) are also exposed for standalone builds when needed, without forcing a driver on consuming applications.

Route permissions (permission feature)

Declare permissions where the routes are defined; they are enforced (401/403) and recorded in the permission matrix once:

ctx.enforce_with::<User>();
ctx.module_with("categories", "categories", &[Operation::Access], |m| {
    m.get("/", index).permission(&[Operation::Read]).name("index"); // call permission() BEFORE name()
});
let matrix = shared_route_index.permissions(); // feed RouteAccess

ctx.require(&[ops], |g| ..) adds a permission group without changing URLs or names.

Setup

use laravel::Application;
use saola_kit::SaolaServiceProvider;
use saola_kit::context::{ContextSpec, RouteEntry};

let provider = SaolaServiceProvider::new()
    .with_context(ContextSpec::new("web").with_hosts(["vn360plus.com"]))
    .with_route(RouteEntry::new("web.home", "/"));

Application::configure()
    .with_providers(move |providers| {
        providers.add(provider);
    });

Sanctum-Compatible Bearer Auth (tokens feature)

use laravel::auth::Authenticate;
use saola_kit::tokens::{SanctumGuard, require_ability};

// In src/app.rs (.with_services):
app.instance(
    SanctumGuard::<User>::new(|id| async move { User::find(id).await })
        .with_tokenable_type("App\\Modules\\User\\Models\\User"),
);

// In src/routes/api.rs:
route.middleware(Authenticate::via::<SanctumGuard<User>>()).group(|route| {
    route.get("/chat/me", chat::me);
});

SMTP mail (smtp feature)

Enable smtp on the saola-kit Cargo dependency and register SaolaServiceProvider as shown above. Select the SMTP mailer in the application's environment:

MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_SCHEME=smtp
MAIL_PORT=587
MAIL_USERNAME=mailer
MAIL_PASSWORD=replace-with-your-smtp-password
MAIL_FROM_ADDRESS=notifications@example.com
MAIL_FROM_NAME="Example"
MAIL_SCHEME Connection Default port
smtp or omitted Requires STARTTLS 587
smtps TLS from connection start 465
none Plaintext for loopback relays without credentials 25

Set both credential variables for authenticated servers. Omit both for an unauthenticated relay. Use Laravel's usual mail::to(...).send(...) and mail::to(...).queue(...) APIs. The transport sends Laravel's MIME unchanged, including attachments, and passes Bcc recipients only in the SMTP envelope.

Server-side rendering (view feature)

saola-compiler emits a Jinja template per .sao view (rust-saoc view-ssr X.sao) with the hydration markers the client expects. Put the compiled templates in a view namespace and render the page on first load:

render("web.landing", props)
    .shell("web::shell")            // prints {{ saola_ssr_html | safe }}, {{ saola_ssr_meta_title }} …
    .ssr("web::landing")            // compiled template
    .ssr_system("__layout__", "web::layouts.")   // prefixes used by @extends/@include
    .ssr_system("__component__", "web::components.")
    .into_response_for(&request)

System view as the parent layout. The recommended form is ssr_document(template): the template renders the whole HTML document. A layout that wraps its body in @pageStart … @pageEnd is compiled to {% extends (__system__ ~ 'app') %} + {% block page %}, so the chain page → layout → _system.app ends in your system view (resources/views/_system/app.html), which declares {% block page %} plus overridable blocks such as section__meta_title (a page's @section('meta:title', …) overrides it). The system view receives saola_locale, saola_title, saola_context, saola_boot_json, saola_envelope_json and saola_ssr_boot_json; __system__ defaults to _system..

SPA/JSON requests keep getting the envelope; an SSR failure is logged and the shell still boots the client. @section('meta:title' | 'meta:description' | …) become saola_ssr_meta_title, saola_ssr_meta_description, … Register site helpers with SaolaServiceProvider::with_ssr_site(Arc<dyn SsrSite>). The helper list is a contract with saola_compiler::view::SSR_HELPERS; tests/ssr_contract.rs fails when one is missing.