51Degrees JavaScript builder
The JavaScript builder element renders a client-side JavaScript include from
the JSON payload produced by the [fiftyone_json_builder] crate. The
generated script creates a global manager object on the client device, runs
any JavaScript-typed properties the JSON carries, and (when a callback URL is
configured) posts the evidence it gathers back to the server for a refreshed
result. It implements the
javascript-builder specification.
The template
The script is rendered from a single Mustache template,
JavaScriptResource.mustache, embedded at compile time with include_str!.
Rendering uses a small,
pure-safe-Rust Mustache renderer (in this crate's mustache module) with
HTML escaping disabled, so the JSON payload, the callback URL and the object
name reach the client verbatim.
Configuration and per-request overrides
[JavaScriptBuilderElementBuilder] sets the host, endpoint, protocol, object
name, cookie behavior and minification. Several of those can be overridden
per request through evidence (query.fod-js-object-name,
query.fod-js-enable-cookies, header.host and header.protocol). See
[JavaScriptBuilderElement] for the full derivation rules.
Minification
With the default-on minify feature the rendered script is minified by the
oxc toolchain (see the minify module). A minification failure falls back to
the unminified script, so valid JavaScript is always served. The set_minify
builder flag turns minification off for an element, and building the crate
with default-features = false drops the oxc dependency entirely.
A worked pipeline
use Arc;
use ;
use JsonBuilderElement;
use ;
let pipeline = builder
.add_element
.add_element
.build
.unwrap;
let mut data = pipeline.create_flow_data_with;
data.process.unwrap;
let js = data.get.unwrap.javascript.to_owned;
assert!;