Files
jerapah-flow/packages/server/scripts/jsonata.js
T
nsrb 94ba931d9b feat(scripts): add fetch-http script for HTTP requests
Introduce a new fetch-http script that facilitates making HTTP requests with configurable methods, headers, and body. The script includes validation for input parameters and logs the request and response details. This addition enhances the server's capability to interact with external APIs and services.
2026-08-15 17:09:28 +07:00

28 lines
830 B
JavaScript

import jsonata from "jsonata";
async function jsonataFn(ctx) {
log.info({ctx}, "jsonata: context")
log.info("jsonata: evaluating expression %s", ctx.config.expression);
const expression = jsonata(ctx.config.expression);
const result = await expression.evaluate(ctx.data);
log.info({result}, "jsonata: expression result");
return result;
}
jsonataFn.meta = {
description: "Evaluate a JSONata expression against ctx.data and return the result as the next context",
config: {
expression: { type: "string", required: true, description: "JSONata expression" },
},
input: {},
output: {},
example: {
data: { title: "Hello", url: "https://example.com" },
config: {
expression: '{"data": {"title": title, "message": title, "attach": url}}',
},
},
};
export default jsonataFn;