// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Core.Rules.Deprecated;
using Squidex.Flows;
using Squidex.Infrastructure.Reflection;
#pragma warning disable CS0618 // Type or member is obsolete
namespace Squidex.Extensions.Actions.Script;
[FlowStep(
Title = "Script",
IconImage = "",
IconColor = "#3389ff",
Display = "Execute a script",
Description = "Execute custom code in Javascript.")]
[NoRetry]
public sealed record ScriptFlowStep : FlowStep, IConvertibleToAction
{
[Script]
[Display(Name = "Script", Description = "The script to execute.")]
[Editor(FlowStepEditor.TextArea)]
public string? Script { get; set; }
public override async ValueTask ExecuteAsync(FlowExecutionContext executionContext,
CancellationToken ct)
{
if (!string.IsNullOrWhiteSpace(Script))
{
await executionContext.RenderAsync($"Script({Script})", executionContext.Context);
}
return Next();
}
public RuleAction ToAction()
{
return SimpleMapper.Map(this, new ScriptAction());
}
}