feat(scripts): enhance script return structure and context handling

- 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.
This commit is contained in:
2026-08-15 22:32:42 +07:00
parent e8e1cf383d
commit 43e9370638
36 changed files with 766 additions and 337 deletions
@@ -10,7 +10,11 @@ scripts:
- script: jsonata.js
config:
expression: |
{"data": {"title": httpResponse.title, "message": httpResponse.title, "attach": httpResponse.url}}
{
"title": data.httpResponse.title,
"message": data.httpResponse.title,
"attach": data.httpResponse.url
}
- fetch-binary.js
- script: ntfy.js
config:
@@ -13,11 +13,9 @@ scripts:
config:
expression: |
{
"data": {
"title": item.title,
"message": item.contentSnippet & "\n" & item.link,
"attach": item.mediaContent.url ? item.mediaContent.url : (item.mediaContent.$ ? item.mediaContent.$.url : undefined)
}
"title": data.item.title,
"message": data.item.contentSnippet & "\n" & data.item.link,
"attach": data.item.mediaContent.url ? data.item.mediaContent.url : (data.item.mediaContent.$ ? data.item.mediaContent.$.url : undefined)
}
- script: ntfy.js
config:
@@ -14,18 +14,16 @@ scripts:
config:
expression: |
{
"data": {
"to": $exists(to) ? to : "nasyarobby@gmail.com",
"from": from,
"subject": subject,
"text": $exists(text) ? text : ($exists(body) ? body : message),
"html": html,
"cc": cc,
"bcc": bcc,
"replyTo": replyTo,
"priority": priority,
"headers": headers
}
"to": $exists(data.to) ? data.to : "nasyarobby@gmail.com",
"from": data.from,
"subject": data.subject,
"text": $exists(data.text) ? data.text : ($exists(data.body) ? data.body : data.message),
"html": data.html,
"cc": data.cc,
"bcc": data.bcc,
"replyTo": data.replyTo,
"priority": data.priority,
"headers": data.headers
}
- script: send-email.js
config:
+1 -1
View File
@@ -3,7 +3,7 @@ scripts:
- get-current-time.js
- script: jsonata.js
config:
expression: '{"data": {"message": datetime & " " & processId}}'
expression: '{"message": data.datetime & " " & data.processId}'
- ntfy.js
triggers:
- type: HTTP
@@ -19,11 +19,11 @@ scripts:
needs: [time, comic]
config:
expression: |
{"data": {
"title": comic.httpResponse.title,
"message": time.datetime & " " & comic.httpResponse.title,
"attach": comic.httpResponse.url
}}
{
"title": data.comic.httpResponse.title,
"message": data.time.datetime & " " & data.comic.httpResponse.title,
"attach": data.comic.httpResponse.url
}
- id: notify
script: ntfy.js
@@ -2,10 +2,10 @@ name: time to ntfy example
description: |
this workflow will send a message to ntfy with the current time
scripts:
- get-current-time.js
- script: get-current-time.js
- script: ntfy.js
config:
url: https://ntfy.sh/scrunner
url: https://n.0dev.web.id/system
triggers:
- type: HTTP
method: POST
+2 -4
View File
@@ -16,10 +16,8 @@ scripts:
config:
expression: |
{
"data": {
"title": httpResponse.customer_name,
"message": httpResponse.customer_name & " : " & httpResponse.status
}
"title": data.httpResponse.customer_name,
"message": data.httpResponse.customer_name & " : " & data.httpResponse.status
}
- script: ntfy.js
config: