1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* *********************************************************************
* This Original Work is copyright of 51 Degrees Mobile Experts Limited.
* Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
* Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
*
* This Original Work is licensed under the European Union Public Licence
* (EUPL) v.1.2 and is subject to its terms as set out below.
*
* If a copy of the EUPL was not distributed with this file, You can obtain
* one at https://opensource.org/licenses/EUPL-1.2.
*
* The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
* amended by the European Commission) shall be deemed incompatible for
* the purposes of the Work and the provisions of the compatibility
* clause in Article 5 of the EUPL shall not apply.
*
* If using the Work as, or as part of, a network application, by
* including the attribution notice(s) required under Article 5 of the EUPL
* in the end user terms of the application under an appropriate heading,
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */
//! [](https://51degrees.com/?utm_source=docs.rs&utm_medium=docs&utm_campaign=rust&utm_content=fiftyone-javascript-builder-lib.rs&utm_term=logo)
//!
//! # 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](https://github.com/51Degrees/specifications/blob/main/pipeline-specification/pipeline-elements/javascript-builder.md).
//!
//! ## 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 std::sync::Arc;
//! use fiftyone_pipeline_core::{Evidence, Pipeline};
//! use fiftyone_json_builder::JsonBuilderElement;
//! use fiftyone_javascript_builder::{JavaScriptBuilderElement, JAVASCRIPT_BUILDER_DATA_KEY};
//!
//! let pipeline = Pipeline::builder()
//! .add_element(Arc::new(JsonBuilderElement::new()))
//! .add_element(Arc::new(JavaScriptBuilderElement::new()))
//! .build()
//! .unwrap();
//!
//! let mut data = pipeline.create_flow_data_with(
//! Evidence::builder().add("header.host", "localhost").build(),
//! );
//! data.process().unwrap();
//!
//! let js = data.get(JAVASCRIPT_BUILDER_DATA_KEY).unwrap().javascript().to_owned();
//! assert!(js.contains("fiftyoneDegreesManager"));
//! ```
pub use JavaScriptBuilderElementBuilder;
pub use ;
pub use ;
pub use JavaScriptBuilderElement;
pub use JavaScriptResource;