Member erase (Marty 2026-11-15, ticket LS-1021): POST /api/admin/erase {email, dryRun (default true), force} + the hub's member.erased event

erase.js runs inside the app so the documents modules keep in memory and the MySQL docs rows stay consistent. Refused
unless force: a main wallet, an on-chain member number, positions, a team here, ads running or queued. Removes the
account, their spin links with every click row in rot_hits and conversions (rotator.eraseOwner, docstore.rowsWhere),
and scrubs every document that mentions them with scrub.js (same file as InstantAdPay) through the owning module's live
copy: accounts, audiences, coach, convtrack, earned (unspent credits go away), hubsync, iapsync, mail-intro, postbacks,
registry, rotator, sponsorfollow; others (updates-log, ...) through docstore. A 30-day email-hash tombstone (erase.json)
stops the InstantAdPay registry sync and hub events from bringing them back; the log keeps hashes and counts only.
hubsync handles member.erased {emailHash}. qa/erase.test.cjs 6 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 12:29:33 -06:00
parent e2af298317
commit f4789156b8
18 changed files with 349 additions and 14 deletions
+14 -1
View File
@@ -194,4 +194,17 @@ async function claim(key) {
// SIGTERM during a deploy: write what is pending, then exit
async function drain(ms) { const end = Date.now() + (ms || 8000); while ((pending.size || flushing || rowQ.length || rowBusy) && Date.now() < end) { await flush().catch(() => {}); await new Promise(r => setTimeout(r, 100)); } }
function view() { return Object.assign({ ready, writer, documents: cache.size, pending: pending.size, rowQueue: rowQ.length, rowTables: Object.fromEntries([...ROWS].map(([k, v]) => [k, v.length])), bytes: [...cache.values()].reduce((t, d) => t + d.body.length, 0) }, stats); }
module.exports = { install, init, drain, flush, view, nameOf, rows, rowPut, rowDel, isOn, claim };
const names = () => [...cache.keys()]; // every document name (the member erase walks them all, 2026-11-15)
// member erase (2026-11-15): count or delete the rows of a row table whose JSON body has `field` (e.g. '$.r') in `values`. Waits
// for queued row writes first, so a click queued before the erase cannot land after it.
async function rowsWhere(table, field, values, del) {
if (!pool || !values.length) return 0;
for (let i = 0; i < 100 && (rowQ.length || rowBusy); i++) await new Promise(r => setTimeout(r, 100));
const vals = values.map(String); const where = 'CAST(JSON_UNQUOTE(JSON_EXTRACT(body, ?)) AS CHAR) IN (?)';
if (!del) { const [[r]] = await pool.query('SELECT COUNT(*) n FROM `' + table + '` WHERE ' + where, [field, vals]); return Number(r.n); }
if (!writer) return 0;
const [r] = await pool.query('DELETE FROM `' + table + '` WHERE ' + where, [field, vals]);
const mem = ROWS.get(table); if (mem) { const k = field.replace(/^\$\./, ''); ROWS.set(table, mem.filter(x => !vals.includes(String(x[k])))); }
return Number(r.affectedRows || 0);
}
module.exports = { install, init, drain, flush, view, nameOf, rows, rowPut, rowDel, isOn, claim, names, rowsWhere };