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.
28 lines
830 B
JavaScript
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;
|