Update tempContext to use full globalVMContext and globalVariableContext

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>
This commit is contained in:
2026-03-07 11:17:19 -06:00
parent 6e2e385d6a
commit 6df1d49e9a

View File

@@ -89,12 +89,13 @@ function loadGlobalVariableFunctions() {
const code = readFileSync(filePath, "utf-8"); const code = readFileSync(filePath, "utf-8");
const script = new vm.Script(code, { filename: file }); const script = new vm.Script(code, { filename: file });
// Execute in context with crypto and console // Execute in context with all VM globals and previously loaded variables
// Expects file to return an object via IIFE // Allows function modules to access same dependencies as proxy.js
const tempContext = vm.createContext({ const tempContext = vm.createContext({
crypto, ...globalVMContext,
console: logger, ...globalVariableContext,
}); });
const exportedObject = script.runInContext(tempContext); const exportedObject = script.runInContext(tempContext);
globalVariableContext[functionName] = exportedObject; globalVariableContext[functionName] = exportedObject;