Reverse registry sync: LinkSpin-first members arrive on InstantAdPay as waiting accounts

POST /api/partner/registry (same HMAC LS_SYNC_SECRET scheme LinkSpin accepts from us, 10-minute window) feeds
lsinbound.js: an email already on InstantAdPay keeps its sponsor and only gets empty fields filled (username if free
and allowed, wallet if no other account or linked position holds it, profile); a new email becomes a waiting shell
(joinedVia linkspin) under its LinkSpin sponsor, building the sponsor's shell upward from known rows (25 levels),
remembering a sponsor whose row has not arrived and binding it later, refusing sponsor loops. No mail, notices or chain.

Unclaimed shells are left out of accounts.listAll by default (tank, coach nudges, Friday/Wednesday broadcasts, member
update audiences, leaderboard, 1,000-member milestone count); the admin members table and lssync ask for them. The first
sign-in claims the shell: the sign-up anti-fraud checks run then, a sponsorless shell takes the link used, lastSeen set.

Loop guard: lssync mutes an email while its LinkSpin row is applied, then records the result as already pushed when it
equals what LinkSpin sent; touch() now skips rows whose hash is unchanged. Status: GET /api/admin/lsinbound (also under
/api/admin/lssync as inbound).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-15 10:44:53 -05:00
parent ae72a06a85
commit d86f2fbcf8
4 changed files with 220 additions and 13 deletions
+38 -7
View File
@@ -42,6 +42,7 @@ const videosweep = require('./videosweep');
const sbcheck = require('./sbcheck');
const reach = require('./reach');
const lssync = require('./lssync');
const lsinbound = require('./lsinbound'); // reverse registry sync: LinkSpin-first members arrive as waiting accounts (2026-10-15)
const gamestats = require('./gamestats');
const marks = require('./marks');
const feedgroup = require('./feedgroup'); // one proof-feed message per purchase: buyer, package, then the tier payouts // one-time claims shared across running instances (deploy overlap) // Google Safe Browsing screen on advertiser destinations
@@ -552,6 +553,7 @@ async function boot() {
tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com' });
// LinkSpin registry sync (2026-10-08): every account change is pushed to LinkSpin within seconds; a 2-minute reconcile catches the rest
lssync.init({ dataDir: DATA_DIR, accounts }); accounts.onChange(email => lssync.touch(email));
lsinbound.init({ dataDir: DATA_DIR, accounts, lssync });
setTimeout(() => lssync.tick().catch(e => console.error('lssync', e.message)), 2 * 60 * 1000);
setInterval(() => lssync.tick().catch(e => console.error('lssync', e.message)), 2 * 60 * 1000);
walletnudge.init({ dataDir: DATA_DIR, accounts, mailer, optedIn: updates.optedIn, site: 'https://instantadpay.com',
@@ -725,6 +727,16 @@ function parseCookies(req) {
}
return out;
}
// First sign-in to a waiting account made from a LinkSpin row (lsinbound.js): it becomes the person's own ordinary account.
// Its LinkSpin sponsor stands; one that arrived with no sponsor at all takes the link they signed in through, exactly as a
// brand-new account would (first InstantAdPay touch). Marked seen at once, so the sweeps count it from here on.
async function claimShell(email, shell, ref) {
try {
if (!shell.sponsorRef && ref) { const tok = String(ref).toLowerCase(); let sp = await accounts.byCode(tok); if (!sp) sp = await accounts.byUsername(tok); if (sp && sp.email !== email) await accounts.setSponsorRef(email, ref); }
await accounts.touchSeen(email);
console.log('linkspin waiting account claimed', email.replace(/^(.).*(@.*)$/, '$1***$2'), shell.sponsorRef ? 'sponsor ' + shell.sponsorRef : (ref ? 'sponsor from link ' + ref : 'no sponsor'));
} catch (e) { console.error('claimShell', e.message); }
}
function isAdmin(req) {
const h = req.headers.authorization || '';
if (h === 'Bearer ' + ADMIN_PASSWORD) return true;
@@ -2063,8 +2075,9 @@ const server = http.createServer(async (req, res) => {
if (fraud.isSuspended(e)) return json(res, 403, { error: 'This account is suspended. Contact support.' });
let fraudFlags = [];
const existing = await accounts.byEmail(e);
if (!existing) { // anti-fraud checks apply to NEW accounts only (Marty, 2026-09-16: one account per person)
let spAcct = null; if (ref) { try { spAcct = await accounts.byCode(String(ref).toLowerCase()); if (!spAcct) spAcct = await accounts.byUsername(String(ref).toLowerCase()); } catch (err) {} }
const claim = accounts.isUnclaimedShell(existing); // a waiting LinkSpin account: this sign-in is its owner's real sign-up
if (!existing || claim) { // anti-fraud checks apply to NEW accounts only (Marty, 2026-09-16: one account per person)
let spAcct = null; if (claim) { try { spAcct = await accounts.sponsorOf(e); } catch (err) {} } else if (ref) { try { spAcct = await accounts.byCode(String(ref).toLowerCase()); if (!spAcct) spAcct = await accounts.byUsername(String(ref).toLowerCase()); } catch (err) {} }
const fc = await fraud.checkSignup(req, spAcct, siteConfig(), e);
fraudFlags = fc.flags;
// an approved exception is worth a log line: it is the difference between "the guard
@@ -2075,7 +2088,8 @@ const server = http.createServer(async (req, res) => {
const r = await accounts.ensure(e, ref, via, joinedRef); // first touch wins; existing accounts unchanged
if (r.error) return json(res, 400, r);
if (r.created) pendingSponsor.del(e);
if (r.created) { fraud.recordSignup(e, req, fraudFlags).catch(() => {}); if (fraudFlags.length) fraudAlert(e, { flags: fraudFlags, ip: fraud.ipOf(req) }, null, false); }
if (claim) await claimShell(e, existing, ref);
if (r.created || claim) { fraud.recordSignup(e, req, fraudFlags).catch(() => {}); if (fraudFlags.length) fraudAlert(e, { flags: fraudFlags, ip: fraud.ipOf(req) }, null, false); }
else fraud.recordSeen(e, req).catch(() => {});
// the lead is in the door: queue the getting-started sequence (opt-in box is pre-checked on both forms)
if (r.created && (b.followups || b.newsletter)) drip.enqueue(e, ref, via).catch(() => {});
@@ -2155,8 +2169,9 @@ const server = http.createServer(async (req, res) => {
const joinedRef = (pend && pend.joinedRef) || (g.host() + (srcTag ? '/' + srcTag : '')); // e.g. driprunner.app/adsterra
let fraudFlags = [];
const existing = await accounts.byEmail(e);
if (!existing) { // one account per person, exactly as on the dashboard
let spAcct = null; if (ref) { try { spAcct = await accounts.byCode(ref); if (!spAcct) spAcct = await accounts.byUsername(ref); } catch (err) {} }
const claim = accounts.isUnclaimedShell(existing); // a waiting LinkSpin account: this sign-in is its owner's real sign-up
if (!existing || claim) { // one account per person, exactly as on the dashboard
let spAcct = null; if (claim) { try { spAcct = await accounts.sponsorOf(e); } catch (err) {} } else if (ref) { try { spAcct = await accounts.byCode(ref); if (!spAcct) spAcct = await accounts.byUsername(ref); } catch (err) {} }
const fc = await fraud.checkSignup(req, spAcct, siteConfig(), e);
fraudFlags = fc.flags;
if (fc.allowlisted) console.log('signup allowed by exception list', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'via', fc.allowedBy);
@@ -2164,6 +2179,7 @@ const server = http.createServer(async (req, res) => {
}
const r = await accounts.ensure(e, ref, via, joinedRef); // first touch wins; existing accounts unchanged
if (r.error) return json(res, 400, r, cors);
if (claim) { await claimShell(e, existing, ref); fraud.recordSignup(e, req, fraudFlags).catch(() => {}); if (fraudFlags.length) fraudAlert(e, { flags: fraudFlags, ip: fraud.ipOf(req) }, null, false); }
if (r.created) {
pendingSponsor.del(e);
fraud.recordSignup(e, req, fraudFlags).catch(() => {}); if (fraudFlags.length) fraudAlert(e, { flags: fraudFlags, ip: fraud.ipOf(req) }, null, false);
@@ -2806,7 +2822,22 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/admin/walletnudge' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, walletnudge.adminView()); }
if (p === '/api/admin/reach' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, reach.adminView()); }
if (p === '/api/admin/reach/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); return json(res, 200, await reach.run({ dry: !!(b && b.dry) })); }
if (p === '/api/admin/lssync' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, lssync.adminView()); }
if (p === '/api/admin/lssync' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, Object.assign(lssync.adminView(), { inbound: lsinbound.adminView() })); }
if (p === '/api/admin/lsinbound' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, lsinbound.adminView()); }
// -- reverse registry sync from LinkSpin (2026-10-15): the same signed rows LinkSpin accepts from us (HMAC LS_SYNC_SECRET
// over ts + newline + raw body, 10-minute window). New people become waiting accounts with their LinkSpin line; existing
// accounts keep their sponsor and only get empty fields filled. No mail, no notices, no chain (lsinbound.js).
if (p === '/api/partner/registry' && req.method === 'POST') {
const secret = String(process.env.LS_SYNC_SECRET || '').trim(); if (secret.length < 32) return json(res, 503, { error: 'sync not configured' });
const raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > 2e6) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); });
const ts = String(req.headers['x-ls-ts'] || ''), sig = String(req.headers['x-ls-sig'] || '');
if (!/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 10 * 60000) return json(res, 401, { error: 'stale' });
const want = crypto.createHmac('sha256', secret).update(ts + '\n' + raw).digest('hex');
if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return json(res, 401, { error: 'bad signature' });
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); }
const rows = Array.isArray(b.rows) ? b.rows.slice(0, 500) : [];
return json(res, 200, Object.assign({ ok: true }, await lsinbound.receive(rows)));
}
if (p === '/api/admin/lssync/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); return json(res, 200, await lssync.tick(!!(b && b.force))); }
if (p === '/api/admin/walletnudge/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await walletnudge.tick()); }
if (p === '/api/admin/tank' && req.method === 'GET') {
@@ -4317,7 +4348,7 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/admin/members' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const members = await accounts.listAll(5000); // was 500: older members (igor147, joined 09-12) vanished from the table and its search once the site passed 500 accounts (Marty, 2026-09-29)
const members = await accounts.listAll(5000, { shells: true }); // waiting LinkSpin accounts included (2026-10-15); was 500: older members (igor147, joined 09-12) vanished from the table and its search once the site passed 500 accounts (Marty, 2026-09-29)
// resolve each sponsor token (username, share code or member #) to the sponsor's name
// the lookup covers EVERY account, not the page's slice: built from `members` it called every
// sponsor who joined before the newest 500 a dead link (144 of them, Marty 2026-09-23)