- Added `previewConfigKey` metadata to multiple scripts including fetch-binary, fetch-html, fetch-http, fetch-rss-feed, fingerprint, get-secret, jsonata, ntfy, render-template, and send-email, improving configuration visibility. - Updated the `FieldHelp` and `ScriptCard` components to utilize the new preview configuration, enhancing the user interface for displaying script metadata. - Refactored `TriggerCard` and `WorkflowTestPanel` components to support expanded views, improving user interaction and accessibility of configuration details. - Enhanced the `WorkflowVisualEditor` to manage test panel visibility more effectively. This update improves the overall user experience by providing clearer context and configuration options for scripts and workflows.
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import jsonata from "jsonata";
|
|
|
|
async function triggerWorkflow(ctx) {
|
|
const name = ctx.config?.name;
|
|
if (typeof name !== "string" || name.length === 0) {
|
|
throw new Error("config.name is required");
|
|
}
|
|
|
|
let data = ctx.data;
|
|
const expression = ctx.config?.expression;
|
|
if (typeof expression === "string" && expression.length > 0) {
|
|
const result = jsonata(expression).evaluate(ctx.data);
|
|
data = await result;
|
|
}
|
|
|
|
const started = await $workflows.trigger(name, data);
|
|
const triggered = { name, runId: started?.runId ?? null };
|
|
|
|
const base =
|
|
ctx != null && typeof ctx === "object" && !Array.isArray(ctx) ? { ...ctx } : {};
|
|
|
|
if (base.data != null && typeof base.data === "object" && !Array.isArray(base.data)) {
|
|
return { ...base, data: { ...base.data, triggered } };
|
|
}
|
|
return { ...base, triggered };
|
|
}
|
|
|
|
triggerWorkflow.meta = {
|
|
description:
|
|
"Fire-and-forget another workflow by YAML name (same owner). Destination must declare triggers: [{ type: workflow }]. Optionally reshape ctx.data with JSONata before sending.",
|
|
previewConfigKey: "name",
|
|
config: {
|
|
name: {
|
|
type: "string",
|
|
required: true,
|
|
description: "Destination workflow YAML name (same owner)",
|
|
},
|
|
expression: {
|
|
type: "string",
|
|
required: false,
|
|
description:
|
|
"Optional JSONata expression evaluated against ctx.data; result becomes the destination run input",
|
|
},
|
|
},
|
|
input: {},
|
|
output: {
|
|
triggered: {
|
|
type: "object",
|
|
description: "Record of the kicked-off run ({ name, runId }); under data when data is an object",
|
|
},
|
|
},
|
|
example: {
|
|
data: {
|
|
title: "Hello",
|
|
url: "https://example.com/img.png",
|
|
},
|
|
config: {
|
|
name: "notify-comic",
|
|
expression:
|
|
'{ "title": title, "message": title, "attach": url }',
|
|
},
|
|
},
|
|
};
|
|
|
|
export default triggerWorkflow;
|