001-drive-proxy-adapter #1

Merged
Peter.Morton merged 25 commits from 001-drive-proxy-adapter into main 2026-03-07 12:45:57 -06:00
2 changed files with 26 additions and 22 deletions
Showing only changes of commit 1fecaf52f7 - Show all commits

View File

@@ -5,8 +5,9 @@
* to improve code organization while maintaining vm.Script isolation pattern.
*
* ARCHITECTURE:
* - Loaded by server.js using vm.Script (same as proxy.js)
* - Returns a single object containing all helper functions
* - This file contains the LITERAL BODY of a function
* - server.js wraps this in a function: (function() { <this code> })()
* - Function returns a single object containing all helper functions
* - Injected into globalVariableContext for access by proxy.js
* - NO IMPORTS - All dependencies provided via VM context
*
@@ -286,27 +287,27 @@ return { route: null, error: "Not found", statusCode: 404 };
// Return helpers object with all functions
// =============================================================================
({
// Error classes
DocumentCountExceededError,
return {
// Error classes
DocumentCountExceededError,
// Utilities
generateRequestId,
validateDocumentId,
validateDocumentCount,
// Utilities
generateRequestId,
validateDocumentId,
validateDocumentCount,
// XML
escapeXml,
// XML
escapeXml,
// Error mapping
mapDriveErrorToHttp,
// Error mapping
mapDriveErrorToHttp,
// Sitemap
toSitemapEntry,
transformDocumentsToSitemapEntries,
generateSitemapXML,
generateSitemap,
// Sitemap
toSitemapEntry,
transformDocumentsToSitemapEntries,
generateSitemapXML,
generateSitemap,
// Routing
parseRoute,
});
// Routing
parseRoute,
};

View File

@@ -54,7 +54,10 @@ function loadGlobalVariables() {
jsFiles.forEach((file) => {
const varName = file.replace(".js", "");
const code = readFileSync(join(globalDir, file), "utf-8");
const script = new vm.Script(code, { filename: file });
// Wrap the literal function body in a function and execute
const wrappedCode = `(function() {\n${code}\n})()`;
const script = new vm.Script(wrappedCode, { filename: file });
const context = vm.createContext({ ...globalVMContext, ...globalVariableContext });
// Execute script and capture returned object