- 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.
35 lines
790 B
JavaScript
35 lines
790 B
JavaScript
function passContext(ctx) {
|
|
if (ctx?.context != null && typeof ctx.context === "object" && !Array.isArray(ctx.context)) {
|
|
return { ...ctx.context };
|
|
}
|
|
return {};
|
|
}
|
|
|
|
function getCurrentTime(ctx) {
|
|
const output = {
|
|
datetime: new Date().toISOString(),
|
|
processId: "1234",
|
|
};
|
|
return { output, context: { ...passContext(ctx), ...output } };
|
|
}
|
|
|
|
getCurrentTime.meta = {
|
|
description: "Return the current time as output.datetime",
|
|
config: {},
|
|
input: {},
|
|
output: {
|
|
datetime: { type: "string", description: "ISO timestamp" },
|
|
processId: { type: "string" },
|
|
},
|
|
context: {
|
|
datetime: { type: "string", description: "ISO timestamp" },
|
|
processId: { type: "string" },
|
|
},
|
|
example: {
|
|
data: {},
|
|
config: {},
|
|
},
|
|
};
|
|
|
|
export default getCurrentTime;
|