Network hub listener (hubsync.js), off unless HUB_ENABLED

POST /api/hub/events: signed hub hooks (HUB_SECRET, 5-minute window), each seq applied once, 503 so the hub retries.
member.joined from another door: /v1/resolve the person (climbing to sponsors not here yet) and make waiting accounts
through lsinbound.receive (joinedVia 'hub', joinedRef 'hub:<door>'); existing accounts keep their sponsor and the
difference is listed in /api/admin/hub. wallet.connected fills waiting accounts only; sponsor.changed is a TODO.
Our own new accounts and wallet links go to /v1/join and /v1/wallet from a persisted outbox (hubsync.json), never
in the way of a sign-up. With the flag off nothing is initialised, wired, routed or written; the LinkSpin sync is
unchanged. Test: qa/hubsync.test.cjs against a local network-hub (needs /v1/resolve by id, branch hub-resolve-id).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-12 17:02:45 -06:00
parent 74354346a3
commit 5c896cb782
6 changed files with 465 additions and 6 deletions
+5 -4
View File
@@ -127,7 +127,7 @@ async function place(email, depth, ctx) {
const sp = await sponsorAccount(r.sponsorEmail, depth, ctx);
if (sp) tok = tokenOf(sp); else { s.pending[email] = r.sponsorEmail; ctx.sum.pendingSponsor++; }
}
const x = await A.ensure(email, tok, 'linkspin', 'linkspin');
const x = await A.ensure(email, tok, ctx.via || 'linkspin', ctx.refOf ? ctx.refOf(email) : 'linkspin'); // hubsync.js passes its own via (2026-11-12)
if (!x || x.error) { conflict(ctx.sum, email, 'create', x && x.error); return null; }
a = x.account;
if (x.created) { ctx.sum.created++; wrote = true; note({ type: 'shell', email, sponsor: tok || null, pending: tok ? null : (r.sponsorEmail || null) }); }
@@ -156,10 +156,10 @@ async function resolvePending(ctx) {
note({ type: 'sponsored', email, sponsor: tokenOf(sp) });
}
}
async function handle(rows) {
async function handle(rows, opts) {
const s = load(); s.stats.batches++;
const sum = { rows: 0, noop: 0, created: 0, filled: 0, sponsored: 0, conflicts: 0, pendingSponsor: 0, errors: 0, followed: 0, followKept: 0, tank: 0 };
const ctx = { sum, done: new Set() }; const batch = [];
const ctx = { sum, done: new Set(), via: opts && opts.via, refOf: opts && opts.refOf }; const batch = [];
for (const x of rows || []) { const r = clean(x); if (!r) continue; sum.rows++; s.rows[r.email] = r; batch.push(r); }
if (R.store) for (const r of batch) if (Object.prototype.hasOwnProperty.call(r, 'tank')) { R.store.setRemote(r.email, r.tank); sum.tank++; } // network tank
try {
@@ -176,7 +176,8 @@ async function handle(rows) {
return Object.assign({ proto: SF.PROTO }, sum); // proto 2: this side understands sponsor follow + network tank facts
}
// batches are applied one at a time (two overlapping posts must not both create the same sponsor shell)
function receive(rows) { const run = chain_.then(() => handle(rows)); chain_ = run.catch(() => {}); return run; }
// opts (hubsync.js only): { via, refOf(email) } names where a new waiting account came from; LinkSpin's posts pass none
function receive(rows, opts) { const run = chain_.then(() => handle(rows, opts)); chain_ = run.catch(() => {}); return run; }
function adminView() {
const s = load();
return Object.assign({}, s.stats, { knownRows: Object.keys(s.rows).length, pendingSponsors: Object.keys(s.pending).length, last: s.last || null, lastError: s.stats.lastError || null, recent: s.log.slice(-25).reverse() });