verify-cloud-functions.mjs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * INTERNAL: Cloud Function Builder Script
  3. * Generates self-contained cloud function files for Fmode Parse platform
  4. * (which runs in isolated VM without require/import support)
  5. */
  6. import { readFile, writeFile } from 'node:fs/promises';
  7. import { fileURLToPath } from 'node:url';
  8. import { dirname, resolve } from 'node:path';
  9. const __dirname = dirname(fileURLToPath(import.meta.url));
  10. const cloudFunctionsDir = resolve(__dirname, '..', 'cloud-functions');
  11. // Extract shared helpers from vContext.js (everything after the Constants block)
  12. async function getSharedHelpers() {
  13. const vContext = await readFile(resolve(cloudFunctionsDir, 'vContext.js'), 'utf8');
  14. const helpersStart = vContext.indexOf('// ============= Utilities =============');
  15. const handlerStart = vContext.indexOf('// ============= Handler =============');
  16. return vContext.substring(helpersStart, handlerStart);
  17. }
  18. // Function definitions: file, actions, needs repository functions
  19. const FUNCTIONS = [
  20. { file: 'vContext.js', actions: ['context.get', 'workspace.list', 'workspace.member.update'] },
  21. { file: 'vDomesticVoc.js', actions: ['domestic.snapshot', 'domestic.products.list', 'domestic.product.get', 'domestic.reviews.list', 'domestic.relations.list', 'data-source.list', 'import.list', 'audit.list'] },
  22. { file: 'vSync.js', actions: ['sync.enqueue', 'sync.jobs.list', 'sync.job.get', 'sync.job.events', 'sync.job.retry', 'sync.job.cancel'] },
  23. { file: 'vCompetitor.js', actions: ['competitor.overview', 'competitor.refresh', 'competitor.history', 'competitor.alerts', 'competitor.impacts', 'competitor.tasks.list', 'competitor.tasks.create', 'competitor.tasks.update', 'competitor.run.get'] },
  24. { file: 'vListing.js', actions: ['listing.overview', 'listing.products.list', 'listing.product.get', 'listing.product.score', 'listing.jd-voc-score.get', 'listing.jd-voc-image-review.run'] },
  25. { file: 'vListingJob.js', actions: ['listing.score-job.create', 'listing.score-job.list', 'listing.score-job.get', 'listing.score-job.items', 'listing.score-job.retry', 'listing.score-job.cancel', 'listing.versions.list', 'listing.version.create', 'listing.version.adopt'] },
  26. { file: 'vAnalysis.js', actions: ['analysis.list', 'analysis.create', 'analysis.update', 'insight-decision.list', 'insight-decision.get', 'insight-decision.create'] },
  27. { file: 'vActions.js', actions: ['action.list', 'action.create', 'action.update', 'alert.list', 'alert.create', 'alert.update'] },
  28. { file: 'vKnowledge.js', actions: ['knowledge.products.list', 'knowledge.product.upsert', 'knowledge.product.delete'] },
  29. { file: 'vAI.js', actions: ['ai.status', 'ai.test', 'ai.prompts.list', 'ai.prompt.update', 'ai.chat'] },
  30. { file: 'vUpstream.js', actions: ['upstream.amazon', 'upstream.sorftime', 'upstream.tikhub', 'upstream.domestic'] },
  31. ];
  32. async function main() {
  33. const shared = await getSharedHelpers();
  34. console.log(`Extracted ${shared.split('\n').length} lines of shared code from vContext.js`);
  35. // Currently all files already exist, just verify they have no require statements
  36. for (const func of FUNCTIONS) {
  37. const filePath = resolve(cloudFunctionsDir, func.file);
  38. const content = await readFile(filePath, 'utf8');
  39. const hasRequire = /require\s*\(/.test(content);
  40. const hasImport = /^import\s/m.test(content);
  41. const status = (!hasRequire && !hasImport) ? 'OK' : 'NEEDS FIX';
  42. console.log(` ${status} ${func.file} (${content.length} bytes, ${func.actions.length} actions)`);
  43. }
  44. }
  45. main().catch((error) => {
  46. console.error('Build failed:', error);
  47. process.exitCode = 1;
  48. });