feat: improve webhook integration (customized body and headers)

This commit is contained in:
Carl-Gerhard Lindesvärd
2026-01-23 14:55:10 +01:00
parent f8f470adf9
commit 286f8e160b
20 changed files with 1994 additions and 91 deletions

View File

@@ -0,0 +1,31 @@
/**
* Executes a JavaScript function template
* @param code - JavaScript function code (arrow function or function expression)
* @param payload - Payload object to pass to the function
* @returns The result of executing the function
*/
export function execute(
code: string,
payload: Record<string, unknown>,
): unknown {
try {
// Create the function code that will be executed
// 'use strict' ensures 'this' is undefined (not global object)
const funcCode = `
'use strict';
return (${code})(payload);
`;
// Create function with safe globals in scope
const func = new Function('payload', funcCode);
// Execute the function
return func(payload);
} catch (error) {
throw new Error(
`Error executing JavaScript template: ${
error instanceof Error ? error.message : String(error)
}`,
);
}
}