// Rebuild only with npm ci --ignore-scripts from the audited lock. Releases use committed output. import {build} from 'esbuild'; import {readFile,writeFile,copyFile,mkdir} from 'node:fs/promises'; import {createHash} from 'node:crypto'; await mkdir('vendor',{recursive:true});await mkdir('licenses/vendor',{recursive:true}); const result=await build({stdin:{contents:"export {SendspinCore,SendspinDecoder,loadSendspinClientIdentity} from '@sendspin/sendspin-js';",resolveDir:process.cwd()},bundle:true,format:'esm',platform:'browser',target:'es2022',minify:true,legalComments:'eof',write:false,metafile:true, plugins:[{name:'pcm-only-no-optional-codec',setup(builder){builder.onResolve({filter:/^opus-encdec\//},()=>({path:'disabled-codec',namespace:'pcm-only'}));builder.onLoad({filter:/.*/,namespace:'pcm-only'},()=>({contents:"throw new Error('Optional Opus fallback is not distributed; negotiate PCM'); export default undefined;",loader:'js'}));}}]}); const banner='// @sendspin/sendspin-js 5.0.0 (Apache-2.0), bundled with audited noble MIT dependencies.\n// Modification: optional opus-encdec decoder imports disabled; this build negotiates PCM only.\n// See licenses/vendor and THIRD-PARTY-NOTICES. No source maps or remote imports.\n'; const bytes=banner+result.outputFiles[0].text;await writeFile('vendor/sendspin-5.0.0.mjs',bytes); const licenses=[['@sendspin/sendspin-js','LICENSE'],['@noble/ciphers','LICENSE'],['@noble/curves','LICENSE'],['@noble/hashes','LICENSE']]; for(const [name,file]of licenses)await copyFile(`node_modules/${name}/${file}`,`licenses/vendor/${name.replace(/[@/]/g,'-')}.txt`); const lock=JSON.parse(await readFile('package-lock.json','utf8')); const provenance={sdk:'@sendspin/sendspin-js',version:'5.0.0',sha256:createHash('sha256').update(bytes).digest('hex'),build:'scripts/build_sendspin.mjs',pcm_only:true,optional_opus_fallback_distributed:false, packages:licenses.map(([name])=>({name,version:lock.packages['node_modules/'+name].version,integrity:lock.packages['node_modules/'+name].integrity})),input_files:Object.keys(result.metafile.inputs).filter(p=>p.startsWith('node_modules/'))}; await writeFile('vendor/provenance.json',JSON.stringify(provenance,null,2)+'\n'); console.log('Built pinned PCM-only official SDK bundle and copied notices.');