Merge branch 'hub-listener'
This commit is contained in:
@@ -55,6 +55,7 @@ const lssync = require('./lssync');
|
||||
const lsconv = require('./lsconv'); // conversion tracking: ad click ids pushed to LinkSpin + the member's goals (2026-10-23)
|
||||
const lsreport = require('./lsreport'); // conversion linkage: the LinkSpin click on the account, sign-up / wallet / purchase reported, reporting only (2026-11-07)
|
||||
const lsinbound = require('./lsinbound'); // reverse registry sync: LinkSpin-first members arrive as waiting accounts (2026-10-15)
|
||||
const hubsync = require('./hubsync'); // network hub: members from other doors arrive as waiting accounts, ours are reported (2026-11-12, only with HUB_ENABLED)
|
||||
const SF = require('./sponsorfollow'); // deliberate sponsor changes follow to LinkSpin until chain-bound + one network tank (2026-10-22)
|
||||
const bixpay = require('./bixpay'); // BixPay Visa card: partner-link field, sponsor-follows resolver, tracked clicks (2026-10-29, gated by site config bixpayLive)
|
||||
let follow = null, followStore = null;
|
||||
@@ -540,7 +541,9 @@ async function boot() {
|
||||
marks.ensureTable().catch(e => console.error('marks table', e.message));
|
||||
lsconv.init({ db, dataDir: DATA_DIR });
|
||||
lsreport.init({ db, dataDir: DATA_DIR });
|
||||
accounts.onWalletLinked(e => { lsreport.wallet(e).catch(err => console.error('lsreport wallet', err.message)); });
|
||||
accounts.onWalletLinked(hubsync.enabled()
|
||||
? e => { lsreport.wallet(e).catch(err => console.error('lsreport wallet', err.message)); hubsync.wallet(e); }
|
||||
: e => { lsreport.wallet(e).catch(err => console.error('lsreport wallet', err.message)); });
|
||||
auth.onSeen((email, req) => lsconv.noteSession(email, clientIp(req), req.headers['user-agent'])); // own-click tests on LinkSpin (2026-10-26)
|
||||
setInterval(() => marks.prune().catch(() => {}), 6 * 3600 * 1000).unref();
|
||||
chain.init({ onEvent: ev => {
|
||||
@@ -700,6 +703,8 @@ async function boot() {
|
||||
// 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, follow: followStore, tank: () => tank }); accounts.onChange(email => lssync.touch(email));
|
||||
lsinbound.init({ dataDir: DATA_DIR, accounts, lssync, follow, store: followStore });
|
||||
// network hub (hubsync.js): nothing at all happens here unless HUB_ENABLED is on; the LinkSpin sync above runs either way
|
||||
if (hubsync.enabled()) { hubsync.init({ dataDir: DATA_DIR, accounts, lsinbound }); accounts.onChange(email => { lssync.touch(email); hubsync.touch(email); }); hubsync.start(); }
|
||||
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);
|
||||
setInterval(() => follow.retryPending().catch(e => console.error('sponsorfollow retry', e.message)), 2 * 60 * 1000); // follows waiting on a chain read or a sponsor account
|
||||
@@ -3648,6 +3653,12 @@ const server = http.createServer(async (req, res) => {
|
||||
const rv = await refuel.view(email);
|
||||
return json(res, 200, { ok: true, refuel: rv, facts: rv.on ? await engine.facts({ site: 'iap', adminMember, ads, coach }, email) : null });
|
||||
}
|
||||
// -- network hub hooks (hubsync.js, 2026-11-12): signed with HUB_SECRET (X-Hub-Ts + X-Hub-Sig), 5-minute window. Only with HUB_ENABLED.
|
||||
if (p === '/api/hub/events' && req.method === 'POST' && hubsync.enabled()) {
|
||||
let raw; try { raw = (await readRaw(req, 2e6)).toString('utf8'); } catch (e) { return json(res, 413, { error: 'too big' }); }
|
||||
const r = await hubsync.receive(req.headers, raw); return json(res, r.status, r.body);
|
||||
}
|
||||
if (p === '/api/admin/hub' && req.method === 'GET' && hubsync.enabled()) { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, hubsync.adminView()); }
|
||||
if (p === '/api/partner/registry' && req.method === 'POST') {
|
||||
const sg = await readLsSigned(req, 2e6); if (!sg.body) return json(res, sg.status, { error: sg.error });
|
||||
const b = sg.body;
|
||||
|
||||
Reference in New Issue
Block a user