2023-10-07 10:47:36 +00:00
|
|
|
using Elsa.Expressions.Models;
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Jint;
|
|
|
|
|
|
2023-01-04 19:36:38 +00:00
|
|
|
namespace Elsa.JavaScript.Options;
|
|
|
|
|
|
2023-10-07 10:47:36 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Options for the Jint JavaScript engine.
|
|
|
|
|
/// </summary>
|
2023-01-04 19:36:38 +00:00
|
|
|
public class JintOptions
|
2022-01-12 10:43:46 +00:00
|
|
|
{
|
2023-01-04 19:36:38 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Enables access to any .NET class. Do not enable if you are executing workflows from untrusted sources (e.g. user defined workflows).
|
|
|
|
|
///
|
|
|
|
|
/// See Jint docs for more: https://github.com/sebastienros/jint#accessing-net-assemblies-and-classes
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool AllowClrAccess { get; set; }
|
2022-01-12 10:43:46 +00:00
|
|
|
|
2023-01-04 19:36:38 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Enables access to .NET configuration via the <c>getConfig</c> function.
|
|
|
|
|
/// Do not enable if you are executing workflows from untrusted sources (e.g user defined workflows).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool AllowConfigurationAccess { get; set; }
|
2023-10-07 10:47:36 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of callbacks that are invoked when the Jint engine is created. Use this to configure the engine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<Engine, ExpressionExecutionContext> ConfigureEngineCallback = (_, _) => { };
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the Jint engine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the engine.</param>
|
|
|
|
|
public JintOptions ConfigureEngine(Action<Engine, ExpressionExecutionContext> configurator)
|
|
|
|
|
{
|
|
|
|
|
ConfigureEngineCallback += configurator;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the Jint engine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the engine.</param>
|
|
|
|
|
public JintOptions ConfigureEngine(Action<Engine> configurator)
|
|
|
|
|
{
|
|
|
|
|
return ConfigureEngine((engine, _) => configurator(engine));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers the specified type <c>T</c> with the engine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public JintOptions RegisterType<T>()
|
|
|
|
|
{
|
|
|
|
|
return ConfigureEngine(engine => engine.RegisterType<T>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers the specified type with the engine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public JintOptions RegisterType(Type type)
|
|
|
|
|
{
|
|
|
|
|
return ConfigureEngine(engine => engine.RegisterType(type));
|
|
|
|
|
}
|
2022-01-12 10:43:46 +00:00
|
|
|
}
|