- Introduced a new contract for script returns, requiring an object with `output`, `context`, and `skipRemaining` fields. - Refactored existing scripts to align with the new return structure, ensuring compatibility with the updated context management. - Added utility functions for normalizing context and step results, improving the handling of script execution context. - Updated various scripts (e.g., fetch-binary, fetch-html, fetch-http) to return structured output and context, enhancing data flow and usability. - Improved error handling for script returns, ensuring clearer feedback when invalid structures are returned. This update significantly enhances the flexibility and clarity of script interactions within workflows.
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
function passContext(ctx) {
|
|
if (ctx?.context != null && typeof ctx.context === "object" && !Array.isArray(ctx.context)) {
|
|
return { ...ctx.context };
|
|
}
|
|
return {};
|
|
}
|
|
|
|
function mergeData(data) {
|
|
if (data != null && typeof data === "object" && !Array.isArray(data)) {
|
|
return { ...data };
|
|
}
|
|
return {};
|
|
}
|
|
|
|
async function getSecret(ctx) {
|
|
const name = ctx.config?.name;
|
|
if (typeof name !== "string" || name.length === 0) {
|
|
throw new Error("config.name is required");
|
|
}
|
|
const as =
|
|
typeof ctx.config?.as === "string" && ctx.config.as.length > 0
|
|
? ctx.config.as
|
|
: name;
|
|
|
|
const value = await $secrets.get(name);
|
|
const extra = { [as]: value };
|
|
return {
|
|
output: { ...mergeData(ctx.data), ...extra },
|
|
context: { ...passContext(ctx), ...extra },
|
|
};
|
|
}
|
|
|
|
getSecret.meta = {
|
|
description:
|
|
"Load a named secret for this workflow owner onto output and context. The value is wrapped and redacted in logs.",
|
|
previewConfigKey: "name",
|
|
config: {
|
|
name: {
|
|
type: "string",
|
|
required: true,
|
|
description: "Secret name (per owner)",
|
|
},
|
|
as: {
|
|
type: "string",
|
|
required: false,
|
|
description: "Field name on output and context (defaults to name)",
|
|
},
|
|
},
|
|
input: {},
|
|
output: {},
|
|
context: {},
|
|
example: {
|
|
data: {},
|
|
config: { name: "ntfy_token", as: "ntfyToken" },
|
|
},
|
|
};
|
|
|
|
export default getSecret;
|