51Degrees Pipeline for .NET

FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement Class Reference

Detailed Description

JavaScript Builder Element generates a JavaScript include to be run on the client device.

See the Specification

Inheritance diagram for FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement:

[legend]

Collaboration diagram for FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement:

[legend]

Public Member Functions

 JavaScriptBuilderElement (ILogger< JavaScriptBuilderElement > logger, Func< IPipeline, FlowElementBase< IJavaScriptBuilderElementData, IElementPropertyMetaData >, IJavaScriptBuilderElementData > elementDataFactory, string endpoint, string objectName, bool enableCookies, bool minify, string host=null, string protocol=null)
 Default constructor.
IJavaScriptBuilderElementData GetFallbackResponse (IFlowData data, IJsonBuilderElementData jsonData)
 Default process method.

Public Member Functions inherited from FiftyOne.Pipeline.Core.FlowElements.FlowElementBase< T, TMeta >

 FlowElementBase (ILogger< FlowElementBase< T, TMeta > > logger)
 Constructor.
 FlowElementBase (ILogger< FlowElementBase< T, TMeta > > logger, Func< IPipeline, FlowElementBase< T, TMeta >, T > elementDataFactory)
 Constructor.
virtual void Process (IFlowData data)
 Process the given IFlowData with this FlowElement.
virtual void AddPipeline (IPipeline pipeline)
 Called when this element is added to a pipeline.
void Dispose ()
 Dispose.

Static Public Member Functions

static bool IsValidObjectName (string name)
 True if name can be used as the name of the object the client script creates, meaning it is a JavaScript identifier made of ASCII letters, digits, underscores and dollar signs, does not start with a digit, and is not a reserved word.

Static Public Attributes

const string DEFAULT_ELEMENT_DATA_KEY = "javascriptbuilderelement"
 The default element data key that will be used for this element.
const string FODID_ELEMENT_DATA_KEY = "FODid"
 The element data key that both 51Did engines return.

Protected Member Functions

override void ManagedResourcesCleanup ()
 Cleanup any managed resources.
override void ProcessInternal (IFlowData data)
 Default process method.
virtual Dictionary< string, string > GetParameters (IFlowData data)
 Generate any required parameters for the JSON request.
virtual int GetSequence (IFlowData data)
 Get the sequence from the Sequence Element's data.
virtual string GetSessionId (IFlowData data)
 Get the session id from the Sequence Element's data.
virtual bool RenderUserPrompt (IFlowData data)
 Decide whether the rendered script carries the block that asks the visitor's preference platform for an answer, which is what a 51Did is created from.
void BuildJavaScript (IFlowData data, Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider, string jsonObject, string sessionId, int sequence, bool supportsPromises, bool supportsFetch, string url, string parameters)
 Build the JavaScript content and add it to the supplied IFlowData instance.
Func< IJavaScriptBuilderElementData > GetOrAddToData (IFlowData data)
 Delegates to IFlowData.GetOrAdd<T>(string, Func<IPipeline, T>).
void BuildJavaScript (IFlowData data, Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider, string jsonObject, string sessionId, int sequence, bool supportsPromises, bool supportsFetch, Uri url, string parameters)
 Build the JavaScript content and add it to the supplied IFlowData instance.
void BuildJavaScript (IFlowData data, Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider, string jsonObject, string sessionId, int sequence, bool supportsPromises, bool supportsFetch, string protocol, string host, string endpoint, string parameters)
 Build the JavaScript content and add it to the supplied IFlowData instance, with a callback URL built from the protocol, host and endpoint.
void BuildJavaScript (IFlowData data, string jsonObject, string sessionId, int sequence, bool supportsPromises, bool supportsFetch, Uri url, string parameters)
 Build the JavaScript content and add it to the supplied IFlowData instance.
override void UnmanagedResourcesCleanup ()
 Cleanup any unmanaged resources.

Protected Member Functions inherited from FiftyOne.Pipeline.Core.FlowElements.FlowElementBase< T, TMeta >

void ProcessInternal (IFlowData data)
 Abstract method called by Process(IFlowData).
virtual T CreateElementData (IPipeline pipeline)
 Method used to create element data instances that are populated by this flow element.
void ManagedResourcesCleanup ()
 Cleanup any managed resources that the element is using.
void UnmanagedResourcesCleanup ()
 Cleanup any unmanaged resources that the element is using.
virtual void Dispose (bool disposing)
 Dispose of any resources.

Static Protected Member Functions

static Func< IJsonBuilderElementData > GetJSONFromData (IFlowData flowData)
 Attempts to extract IJsonBuilderElementData from data.

Properties

string Host [get]
 The host name to use when creating a callback URL.
string Endpoint [get]
 The end point (i.e.
string Protocol [get]
 The protocol to use when creating a callback URL.
string ObjName [get]
 The name of the JavaScript object that will be created.
bool EnableCookies [get]
 If set to false, the JavaScript will automatically delete any cookies prefixed with 51D_.
HashSet< string > ExcludedParameters [get]
 These parameters are excluded from the parameters object used to configure the JavaScript as they are added explicitly.
override string ElementDataKey [get]
 Key to identify engine.
override IEvidenceKeyFilter EvidenceKeyFilter [get]
 Publicly accessible EvidenceKeyFilter.
override IList< IElementPropertyMetaData > Properties [get]
 Publicly accessible Property list.

Properties inherited from FiftyOne.Pipeline.Core.FlowElements.FlowElementBase< T, TMeta >

ILogger< FlowElementBase< T, TMeta > > Logger [get]
 The logger for this instance.
IReadOnlyList< IPipeline > Pipelines [get]
 Get a read only list of the pipelines that this element has been added to.
string ElementDataKey [get]
 The string name of the key used to access the data populated by this element in the IFlowData.
IEvidenceKeyFilter EvidenceKeyFilter [get]
 A list of all the evidence keys that this Flow Element can make use of.
IList< TMeta > Properties [get]
 Details of the properties that this engine can populate.
virtual bool Asynchronous [get]
 True if the element can be run totally asynchronously, false otherwise.
virtual bool IsConcurrent [get]
 True if the element starts multiple threads.
bool IsDisposed [get]
 True if the element has been disposed.
ITypedKey< T > ElementDataKeyTyped [get]
 Get the key used to access the data populated by this element in the IFlowData.

Constructor & Destructor Documentation

◆ JavaScriptBuilderElement()

FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.JavaScriptBuilderElement ( ILogger< JavaScriptBuilderElement > logger,
Func< IPipeline, FlowElementBase< IJavaScriptBuilderElementData, IElementPropertyMetaData >, IJavaScriptBuilderElementData > elementDataFactory,
string endpoint,
string objectName,
bool enableCookies,
bool minify,
string host = null,
string protocol = null )

Default constructor.

Parameters
loggerThe logger.
elementDataFactoryThe element data factory.
endpointSet the endpoint which will be queried on the host. e.g /api/v4/json
objectNameThe default name of the object instantiated by the client JavaScript. Null means the default name, fod. Anything else must be a valid JavaScript identifier, see IsValidObjectName(string).
enableCookiesSet whether the client JavaScript stored results of client side processing in cookies.
minifyIf true, the resulting JavaScript will be minified
hostThe host that the client JavaScript should query for updates. If null or empty then the host from the request will be used
protocolThe protocol, http or https, that the client JavaScript will use when querying for updates. If null or empty then the protocol from the request will be used
Exceptions
PipelineConfigurationExceptionThrown if objectName is not null and is not a valid JavaScript identifier, or if protocol is set and is neither http nor https.

Member Function Documentation

◆ BuildJavaScript() [1/4]

void FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.BuildJavaScript ( IFlowData data,
Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider,
string jsonObject,
string sessionId,
int sequence,
bool supportsPromises,
bool supportsFetch,
string protocol,
string host,
string endpoint,
string parameters )
protected

Build the JavaScript content and add it to the supplied IFlowData instance, with a callback URL built from the protocol, host and endpoint.

The protocol and host usually come from the request, so the URL is checked against the rules in the specification

before the script holds it. A URL that fails them is logged as an error the first time, and the script is built without callback functionality, as it is when the protocol, host or endpoint is not set.

Parameters
dataThe IFlowData instance to populate with the resulting JavaScriptBuilderElementData and additional evidence source
javascriptBuilderElementDataProviderDefines a destination for JavaScriptBuilderElementData to be set into.
jsonObjectThe JSON data object to include in the JavaScript.
sessionIdThe session Id to use in the JavaScript response.
sequenceThe sequence value to use in the JavaScript response.
supportsPromisesTrue to build JavaScript that uses promises. False to build JavaScript that does not use promises.
supportsFetchTrue to build JavaScript that makes use of the fetch API. Otherwise, the template will fall back to using XMLHttpRequest.
protocolThe protocol of the callback URL, http or https in any case.
hostThe host of the callback URL, which can start with user information and end with a port, a path, a query or a fragment.
endpointThe endpoint of the callback URL, joined to the host with one '/'.
parametersThe parameters to append to the URL
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

◆ BuildJavaScript() [2/4]

void FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.BuildJavaScript ( IFlowData data,
Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider,
string jsonObject,
string sessionId,
int sequence,
bool supportsPromises,
bool supportsFetch,
string url,
string parameters )
protected

Build the JavaScript content and add it to the supplied IFlowData instance.

Parameters
dataThe IFlowData instance to populate with the resulting JavaScriptBuilderElementData and additional evidence source
javascriptBuilderElementDataProviderDefines a destination for JavaScriptBuilderElementData to be set into. Allows to store results outside of data (previous parameter).
jsonObjectThe JSON data object to include in the JavaScript.
sessionIdThe session Id to use in the JavaScript response.
sequenceThe sequence value to use in the JavaScript response.
supportsPromisesTrue to build JavaScript that uses promises. False to build JavaScript that does not use promises.
supportsFetchTrue to build JavaScript that makes use of the fetch API. Otherwise, the template will fall back to using XMLHttpRequest.
urlThe callback URL for the JavaScript to send a request to when it has new evidence values to supply.
parametersThe parameters to append to the URL
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

◆ BuildJavaScript() [3/4]

void FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.BuildJavaScript ( IFlowData data,
Func< IJavaScriptBuilderElementData > javascriptBuilderElementDataProvider,
string jsonObject,
string sessionId,
int sequence,
bool supportsPromises,
bool supportsFetch,
Uri url,
string parameters )
protected

Build the JavaScript content and add it to the supplied IFlowData instance.

Parameters
dataThe IFlowData instance to populate with the resulting JavaScriptBuilderElementData and additional evidence source
javascriptBuilderElementDataProviderDefines a destination for JavaScriptBuilderElementData to be set into. Allows to store results outside of data (previous parameter).
jsonObjectThe JSON data object to include in the JavaScript.
sessionIdThe session Id to use in the JavaScript response.
sequenceThe sequence value to use in the JavaScript response.
supportsPromisesTrue to build JavaScript that uses promises. False to build JavaScript that does not use promises.
supportsFetchTrue to build JavaScript that makes use of the fetch API. Otherwise, the template will fall back to using XMLHttpRequest.
urlThe callback URL for the JavaScript to send a request to when it has new evidence values to supply.
parametersThe parameters to append to the URL
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

The URL is written into the script as it is given, apart from percent-encoding each character that could end the string the script holds it in, and is not checked. A subclass that builds its URL from the request uses the overload that takes the protocol, host and endpoint instead.

◆ BuildJavaScript() [4/4]

void FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.BuildJavaScript ( IFlowData data,
string jsonObject,
string sessionId,
int sequence,
bool supportsPromises,
bool supportsFetch,
Uri url,
string parameters )
protected

Build the JavaScript content and add it to the supplied IFlowData instance.

Parameters
dataThe IFlowData instance to populate with the resulting JavaScriptBuilderElementData and additional evidence source
jsonObjectThe JSON data object to include in the JavaScript.
sessionIdThe session Id to use in the JavaScript response.
sequenceThe sequence value to use in the JavaScript response.
supportsPromisesTrue to build JavaScript that uses promises. False to build JavaScript that does not use promises.
supportsFetchTrue to build JavaScript that makes use of the fetch API. Otherwise, the template will fall back to using XMLHttpRequest.
urlThe callback URL for the JavaScript to send a request to when it has new evidence values to supply.
parametersThe parameters to append to the URL
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

◆ GetFallbackResponse()

IJavaScriptBuilderElementData FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetFallbackResponse ( IFlowData data,
IJsonBuilderElementData jsonData )

Default process method.

Parameters
data
jsonData
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

◆ GetJSONFromData()

Func< IJsonBuilderElementData > FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetJSONFromData ( IFlowData flowData)
staticprotected

Attempts to extract IJsonBuilderElementData from data.

Parameters
flowDataIFlowData to extract IJsonBuilderElementData from.
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.
PipelineConfigurationExceptionWraps KeyNotFoundException if thrown.

◆ GetOrAddToData()

Func< IJavaScriptBuilderElementData > FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetOrAddToData ( IFlowData data)
protected

Delegates to IFlowData.GetOrAdd<T>(string, Func<IPipeline, T>).

Parameters
dataFlow data to operate on.
Returns
IJavaScriptBuilderElementData to set IJavaScriptBuilderElementData.JavaScript into.

◆ GetParameters()

virtual Dictionary< string, string > FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetParameters ( IFlowData data)
protectedvirtual

Generate any required parameters for the JSON request.

Any query parameters from this request that were ingested by the Pipeline are added to the request URL by the JavaScript.

Parameters
data
Returns

◆ GetSequence()

virtual int FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetSequence ( IFlowData data)
protectedvirtual

Get the sequence from the Sequence Element's data.

With no Sequence Element in the pipeline there is no such data, and the sequence is 1 whatever the request asked for. The sequence is written into the script as a number, so anything other than a positive 32 bit integer, written as an integer or as a string of digits, gives 1 as well.

Parameters
data
Returns
The sequence, which is always at least 1.

◆ GetSessionId()

virtual string FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.GetSessionId ( IFlowData data)
protectedvirtual

Get the session id from the Sequence Element's data.

With no Sequence Element in the pipeline there is no such data, and the session id is empty whatever the request asked for. The session id is written into the script inside quotes, so one that fails JavaScriptResource.IsValidSessionId(string) is empty as well.

Parameters
data
Returns
The session id, or an empty string.

◆ IsValidObjectName()

bool FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.IsValidObjectName ( string name)
static

True if name can be used as the name of the object the client script creates, meaning it is a JavaScript identifier made of ASCII letters, digits, underscores and dollar signs, does not start with a digit, and is not a reserved word.

Parameters
nameThe name to check.
Returns
True if the name is valid, otherwise false.

◆ ProcessInternal()

override void FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.ProcessInternal ( IFlowData data)
protected

Default process method.

Parameters
data
Exceptions
ArgumentNullExceptionThrown if the supplied flow data is null.

◆ RenderUserPrompt()

virtual bool FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.RenderUserPrompt ( IFlowData data)
protectedvirtual

Decide whether the rendered script carries the block that asks the visitor's preference platform for an answer, which is what a 51Did is created from.

The base renders the block when the pipeline holds a 51Did element offering at least one available property, because a pipeline that cannot return a 51Did has no use for the answer. A host that serves many callers from one pipeline, the cloud being the one that does, overrides this and tests the caller's entitlement per request instead.

Parameters
dataThe IFlowData for the request being served.
Returns
True to render the block, false to leave it out.

Member Data Documentation

◆ FODID_ELEMENT_DATA_KEY

const string FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.FODID_ELEMENT_DATA_KEY = "FODid"
static

The element data key that both 51Did engines return.

It mirrors DidBaseEnginePropertiesBuilder.ComponentName in FiftyOne.Did.Core, which DidCloudEngine returns from its ElementDataKey and the on premise engine in the cloud repository returns as well. The value is copied here because this package must not take a dependency on the 51Did packages, and UserPromptHookTests asserts that the two are still equal.

This is an element data key and not a property component, so the section a page sees in the JSON payload is this value lower cased, which is "fodid". The identifier that the id endpoints take is called "51did" and is a different thing.

Property Documentation

◆ ElementDataKey

override string FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.ElementDataKey
get

Key to identify engine.

Implements FiftyOne.Pipeline.Core.FlowElements.IFlowElement.

◆ Endpoint

string FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.Endpoint
getprotected

The end point (i.e.

the relative URL) to use when creating a callback URL.

◆ EvidenceKeyFilter

override IEvidenceKeyFilter FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.EvidenceKeyFilter
get

Publicly accessible EvidenceKeyFilter.

Implements FiftyOne.Pipeline.Core.FlowElements.IFlowElement.

◆ ExcludedParameters

HashSet<string> FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.ExcludedParameters
getprotected
Initial value:
= new HashSet<string>()
{
}
Constants used by 51Degrees Aspect Engines.
Definition Engines.FiftyOne/Constants.cs:37
const string EVIDENCE_SESSIONID
session id evidence constant.
Definition Engines.FiftyOne/Constants.cs:182
const string EVIDENCE_SEQUENCE
Sequence evidence constant.
Definition Engines.FiftyOne/Constants.cs:197
Definition FiftyOneDataFileConfiguration.cs:27
Definition DataKeyedCacheBase.cs:30

These parameters are excluded from the parameters object used to configure the JavaScript as they are added explicitly.

◆ Properties

override IList<IElementPropertyMetaData> FiftyOne.Pipeline.JavaScriptBuilder.FlowElement.JavaScriptBuilderElement.Properties
get

Publicly accessible Property list.

Implements FiftyOne.Pipeline.Core.FlowElements.IFlowElement< T, TMeta >.