import fs from 'node:fs' import assert from 'node:assert/strict' // Offline migration input must be a captured current-published snapshot, not a draft. const [snapshotPath,outputPath]=process.argv.slice(2) if(!snapshotPath||!outputPath)throw new Error('Usage: node normalize_scanner_parameter_defaults.mjs ') const snapshot=JSON.parse(fs.readFileSync(snapshotPath,'utf8').replace(/^\uFEFF/,'')) assert(snapshot.current?.publishedVersionId&&snapshot.published?.flowData,'A current published version snapshot is required') assert.equal(snapshot.current.publishedVersionId,snapshot.published.id) const graph=JSON.parse(snapshot.published.flowData),before=structuredClone(graph) let nodes=0,changed=0 for(const node of graph.nodes){ if(node.properties?.action!=='SCANNER_PARAMETERS')continue nodes++ const parameter=node.properties.nodeParams?.find(field=>field.name==='requestJson') assert.equal(parameter?.type,'input',`Dynamic scanner request requires a separate review: ${node.id}`) const body=JSON.parse(parameter.input) assert(body&&typeof body==='object'&&!Array.isArray(body)) if(body.brightness===17&&body.pointDistance===0.5)continue parameter.input=JSON.stringify({...body,brightness:17,pointDistance:0.5},null,2) changed++ } assert(nodes>0,'No scanner parameter nodes') // No path, edge, resource assignment or other scanner setting may change. const verified=structuredClone(graph) for(let i=0;ifield.name==='requestJson') verified.nodes[i].properties.nodeParams.find(field=>field.name==='requestJson').input=old.input } assert.deepEqual(verified,before) fs.writeFileSync(outputPath,JSON.stringify(graph,null,2)) console.log(JSON.stringify({flowId:snapshot.current.id,nodes,changed,brightness:17,pointDistance:0.5,pathUnchanged:true}))