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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user