import { randomBytes } from 'node:crypto'; import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { hashTestPassword } from '../server/test-access.js'; import { encryptInventory } from '../server/inventory-bundle.js'; // Run only after the user approves generation/configuration. Secret values are // written to ignored, owner-readable files, never stdout or the source bundle. const root = new URL('../', import.meta.url); const password = randomBytes(24).toString('base64url'); const key = randomBytes(32).toString('base64'); const passwordHash = await hashTestPassword(password); const input = JSON.parse(await readFile(new URL('data/inventory.json', root), 'utf8')); const encrypted = encryptInventory(input, key); await mkdir(new URL('artifacts/', root), { recursive: true }); await writeFile(new URL('artifacts/test-access-secrets.json', root), JSON.stringify({ MAYA_TEST_PASSWORD_HASH: passwordHash, MAYA_INVENTORY_KEY: key }), { flag: 'wx', mode: 0o600 }); await writeFile(new URL('artifacts/maya-test-login.txt', root), `Maya protected inventory test\n\nOpen the app directly (not inside the Hugging Face iframe):\nhttps://ahmedmslti-millie.hf.space\n\nOpen “Über diese Demo” → “Testzugang”.\nTest password: ${password}\n\nAfter login choose “Inventar aktivieren”. Public visitors keep fictional data.\nThe session expires after one hour or a server restart. Do not share this file publicly.\nVoice availability depends on the currently deployed agent role. A mode-compatible shared Maya role can serve both datasets with the same existing account key.\n`, { flag: 'wx', mode: 0o600 }); await writeFile(new URL('data/inventory.enc.json', root), `${JSON.stringify(encrypted)}\n`, { flag: 'wx', mode: 0o644 }); console.log('Prepared encrypted inventory and owner-readable ignored credential files. No secret values printed; no remote change made.');