#!/usr/bin/env node // 🤖 Append one entry to a ledger stream (issue #1224) — the generic CLI over // tools/ledgerstream.mjs. The payload is JSON on stdin; the chain (prev-hash // fingerprints) is maintained for you. // // echo '{"note":"hello"}' | node tools/ledger-append.mjs --writer "Full Name" // // Reads need no credentials (the bucket is public-read); the write uses the // ambient AWS profile — the scoped status-ledger-writer key or your own. // Verify any stream end-to-end with tools/ledger-verify.mjs. import { append } from "./ledgerstream.mjs"; const args = process.argv.slice(2); const ledger = args.find((a) => !a.startsWith("--")); const wi = args.indexOf("--writer"); const writer = wi >= 0 ? args[wi + 1] : null; if (!ledger || !writer || !/^[a-z][a-z0-9-]*$/.test(ledger)) { console.error('usage: echo \'{"…"}\' | node tools/ledger-append.mjs --writer "Full Name"'); process.exit(1); } const stdin = []; for await (const chunk of process.stdin) stdin.push(chunk); const payload = JSON.parse(Buffer.concat(stdin).toString("utf8")); const head = await append(ledger, writer, new Date().toISOString(), payload); console.log(ledger + ": entry " + head.count + " appended, head " + head.head_sha256.slice(0, 12) + "…");