From 6df1d49e9ad09eca88a2b3a247c3d566b2b32763 Mon Sep 17 00:00:00 2001 From: "Peter.Morton" Date: Sat, 7 Mar 2026 11:17:19 -0600 Subject: [PATCH] Update tempContext to use full globalVMContext and globalVariableContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Change tempContext from minimal {crypto, console: logger} - Now uses {...globalVMContext, ...globalVariableContext} - Provides function modules access to all VM globals - Matches the context pattern used for proxy.js Benefits: - Function modules can access all dependencies (axios, jwt, etc.) - Consistent with per-request context pattern - Previously loaded JSON data available to function modules - More flexible for complex function modules Context now includes: - From globalVMContext: URLSearchParams, URL, console, crypto, axios, uuidv4, jwt, xmlBuilder - From globalVariableContext: Previously loaded JSON files and function modules - Allows function modules to depend on other globals if needed Testing: - ✓ Syntax validated - ✓ helpers.js loads correctly with full context - ✓ helpers.generateRequestId() uses crypto from context - ✓ All 11 exports available Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/server.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/server.js b/src/server.js index 303e18a..1a64dce 100644 --- a/src/server.js +++ b/src/server.js @@ -89,12 +89,13 @@ function loadGlobalVariableFunctions() { const code = readFileSync(filePath, "utf-8"); const script = new vm.Script(code, { filename: file }); - // Execute in context with crypto and console - // Expects file to return an object via IIFE + // Execute in context with all VM globals and previously loaded variables + // Allows function modules to access same dependencies as proxy.js const tempContext = vm.createContext({ - crypto, - console: logger, + ...globalVMContext, + ...globalVariableContext, }); + const exportedObject = script.runInContext(tempContext); globalVariableContext[functionName] = exportedObject;