Weekly member email as sectioned HTML (plain-text twin kept); PassiveDrip one-tap hand-off (inert until PD_SSO_SECRET)

- coach.js: weeklyDigest() builds one card per topic (credits, streak, contest, tank, team) with the key number up front and one button; mailer.send takes optional html
- server.js: /api/my/passivedrip mints a signed hand-off (memberId, email, username, verified wallet, sponsor email); Games card for PassiveDrip (admin preview until gamesLive includes passivedrip) with the member's own coins line via the bridge 'member' lookup; sign-in return path
- my.js: card button label, return redirect; v=20261001b

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-01 08:43:22 -05:00
parent dd53d132d6
commit 5a522f0ede
7 changed files with 160 additions and 51 deletions
+100 -43
View File
@@ -205,6 +205,103 @@ async function linkStats(email) {
return { angles: Object.values(rows), sources, totalViews: views.length, totalJoins: joined.length };
}
// ---- the weekly member email (Marty, 2026-09-14; reformatted 2026-10-01 because one long text block was hard to read):
// one section per topic, each with a heading, the number that matters up front and ONE button. Sent as HTML with a
// plain-text twin built from the same sections.
const SITE = 'https://instantadpay.com';
const escH = v => String(v == null ? '' : v).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
const n0 = v => Number(v || 0).toLocaleString('en-US');
async function weeklyDigest(acct, view, lbWeek, tankN, now) {
const name = acct.username ? '@' + acct.username : 'there';
const S = []; // { title, big, bigLabel, lines[], rows[[label, value]], quotes[{to, text}], button{label, url} }
// credits: they sit on positions and each campaign pays from one, so the pooled total alone misleads
// members with linked positions (Jim Watts, 2026-09-27: "561 unspent" but a top-up allowed 19)
try {
const ids = [acct.memberId, ...(await accounts.positions(acct.email)).map(p => p.memberId)].filter(Boolean);
const bal = await X.ads.balances(ids, acct.email);
if (bal.available > 0) {
const onPos = (bal.per || []).filter(p => p.avail > 0).sort((a, b) => b.avail - a.avail);
const loose = (bal.credited || 0) + (bal.earned || 0);
const sec = { title: 'Ad credits ready to use', big: n0(bal.available), bigLabel: 'credits not running yet', lines: [], button: { label: 'Start a campaign', url: SITE + '/my#campaigns' } };
if (onPos.length > 1) {
sec.rows = onPos.map(p => ['Position #' + p.memberId, n0(p.avail)]);
if (loose) sec.rows.push(['Any position can use', n0(loose)]);
sec.lines.push('Each campaign spends from one position. Start from #' + onPos[0].memberId + ' to use the most credits at once.');
}
sec.lines.push('Point the campaign at your invite link so the views bring people to you.');
S.push(sec);
} else if (bal.inCampaigns > 0) S.push({ title: 'Ad credits', big: n0(bal.inCampaigns), bigLabel: 'credits working in live campaigns', lines: ['Everything you have is running. Nice.'] });
} catch (e) {}
// streak
try {
const st = await X.ads.viewStatus(acct.email);
if (st.streakDay > 1) S.push({ title: 'Daily claim streak', big: 'Day ' + st.streakDay, bigLabel: 'of your streak. Today’s claim pays ' + n0(st.claimCredits) + ' credits.', lines: ['Miss a day and the streak starts over.'], button: { label: 'Claim today', url: SITE + '/my#earn' } });
else S.push({ title: 'Free daily credits', lines: ['View five ads and claim once a day. The claim grows 5, 7, 10 credits, then 25 on every seventh day in a row.'], button: { label: 'Start today', url: SITE + '/my#earn' } });
} catch (e) {}
// contest
let first = false;
if (lbWeek && lbWeek.top) {
const me = lbWeek.top.find(r => r.name === '@' + acct.username) || null;
let mine = me; if (!mine) { try { mine = (await X.lb().view('week', acct.email)).me; } catch (e) {} }
first = !!(lbWeek.top.length && lbWeek.top[0].name === '@' + acct.username);
const sec = { title: 'This week’s referral contest', lines: [], button: { label: 'See the leaderboard', url: SITE + '/leaderboard' } };
if (lbWeek.prize) sec.intro = 'Prizes: ' + lbWeek.prize + '.';
if (lbWeek.top.length) sec.rows = lbWeek.top.slice(0, 3).map(r => [r.rank + '. ' + r.name, r.sales + ' sold']);
else sec.lines.push('No sales yet. The first one takes the top spot.');
if (mine) { sec.big = '#' + mine.rank; sec.bigLabel = 'is your place, with ' + mine.sales + ' sold'; }
else sec.lines.push('You are not on the board yet. One $20 package bought by someone you sponsor puts you there.');
S.push(sec);
}
// tank
if (tankN > 0 && acct.memberId) S.push({ title: 'Holding tank', big: n0(tankN), bigLabel: 'member' + (tankN === 1 ? '' : 's') + ' waiting for a sponsor', lines: ['Adopt one from My line and they join your team.'], button: { label: 'Adopt a member', url: SITE + '/my#line' } });
// line (sponsors only)
if (view.directs.length) {
const week = view.directs.filter(d => now - d.joined < 7 * DAY).length;
const sec = { title: 'Your team', rows: [['Direct members', n0(view.directs.length)], ['Joined this week', n0(week)], ['Gone quiet', n0(view.stalled)]], lines: [], button: { label: 'Open My line', url: SITE + '/my#line' } };
const q = view.directs.filter(d => d.stalled).slice(0, 3).map(d => ({ to: d.name, text: d.say.replace('{{name}}', d.name.replace(/^@/, '')) }));
if (q.length) { sec.lines.push('A quick message gets most people moving again. Copy these:'); sec.quotes = q; }
S.push(sec);
}
const subject = first ? 'You are #1 this week on InstantAdPay' : 'Your week on InstantAdPay: credits, streak, contest';
const tip = { text: 'Short on time? The twenty-minute day: claim your set, message one person on your team, check the tank, start one new conversation.', link: SITE + '/blog/the-twenty-minute-day' };
const legal = 'No income is guaranteed. Credits are advertising, not money.';
// plain text twin
const T = ['Hi ' + name + ', here is your week on InstantAdPay.', ''];
for (const s of S) {
T.push(s.title.toUpperCase());
if (s.big) T.push(s.big + ' ' + s.bigLabel);
if (s.intro) T.push(s.intro);
for (const r of s.rows || []) T.push(' ' + r[0] + ': ' + r[1]);
for (const l of s.lines) T.push(l);
for (const q of s.quotes || []) T.push(' To ' + q.to + ': "' + q.text + '"');
if (s.button) T.push(s.button.label + ': ' + s.button.url);
T.push('');
}
T.push(tip.text + ' ' + tip.link, '', 'InstantAdPay · ' + SITE + '/my', legal);
// html
const btn = b => '<a href="' + escH(b.url) + '" style="display:inline-block;background:#1e3a8a;color:#ffffff;text-decoration:none;font-weight:600;font-size:15px;padding:11px 20px;border-radius:8px">' + escH(b.label) + '</a>';
const card = s => '<tr><td style="padding:0 0 14px"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#ffffff;border:1px solid #e3e6ee;border-radius:12px"><tr><td style="padding:18px 20px">'
+ '<div style="font-size:12px;letter-spacing:.06em;text-transform:uppercase;color:#6b7280;font-weight:700;margin:0 0 6px">' + escH(s.title) + '</div>'
+ (s.big ? '<div style="margin:0 0 10px"><span style="font-size:30px;font-weight:800;color:#111827">' + escH(s.big) + '</span> <span style="font-size:15px;color:#4b5563">' + escH(s.bigLabel) + '</span></div>' : '')
+ (s.intro ? '<p style="margin:0 0 8px;font-size:15px;line-height:1.5;color:#374151">' + escH(s.intro) + '</p>' : '')
+ (s.rows ? '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="margin:0 0 10px;font-size:15px">' + s.rows.map(r => '<tr><td style="padding:5px 0;border-bottom:1px solid #f0f1f5;color:#374151">' + escH(r[0]) + '</td><td align="right" style="padding:5px 0;border-bottom:1px solid #f0f1f5;color:#111827;font-weight:700">' + escH(r[1]) + '</td></tr>').join('') + '</table>' : '')
+ s.lines.map(l => '<p style="margin:0 0 10px;font-size:15px;line-height:1.5;color:#374151">' + escH(l) + '</p>').join('')
+ (s.quotes || []).map(q => '<div style="margin:0 0 10px;padding:10px 12px;background:#f5f6fa;border-radius:8px;font-size:14px;line-height:1.5;color:#374151"><b style="color:#111827">To ' + escH(q.to) + '</b><br>' + escH(q.text) + '</div>').join('')
+ (s.button ? '<div style="margin:6px 0 0">' + btn(s.button) + '</div>' : '')
+ '</td></tr></table></td></tr>';
const html = '<!doctype html><html><body style="margin:0;padding:0;background:#f3f4f8">'
+ '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f8"><tr><td align="center" style="padding:20px 12px">'
+ '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif">'
+ '<tr><td style="padding:4px 4px 16px"><div style="font-size:20px;font-weight:800;color:#111827">Your week on InstantAdPay</div><div style="font-size:15px;color:#4b5563;margin-top:4px">Hi ' + escH(name) + ', here is where things stand.</div></td></tr>'
+ S.map(card).join('')
+ '<tr><td style="padding:2px 4px 14px;font-size:14px;line-height:1.5;color:#4b5563">' + escH(tip.text) + ' <a href="' + escH(tip.link) + '" style="color:#1e3a8a">Read how</a></td></tr>'
+ '<tr><td style="padding:0 4px 8px;font-size:12px;color:#9ca3af">InstantAdPay · <a href="' + SITE + '/my" style="color:#9ca3af">' + 'instantadpay.com/my</a><br>' + escH(legal) + '</td></tr>'
+ '</table></td></tr></table></body></html>';
return { subject, text: T.join('\n'), html, sections: S };
}
// ---- automatic nudges to stalled members + weekly digest to sponsors ----
let ticking = false;
const NUDGE_GAP = 5 * DAY;
@@ -242,48 +339,8 @@ async function nudgeTick() {
// audience: sponsors with directs (as before) unless the admin switched the weekly on for every member
const everyone = X.siteConfig && String(X.siteConfig().memberWeeklyEmail || '0') === '1';
if (!everyone && !view.directs.length) { await impl().setDigest(acct.email, now); continue; }
const name = acct.username ? '@' + acct.username : 'there';
const parts = ['Hi ' + name + ', your week on InstantAdPay:'];
// credits
try {
const ids = [acct.memberId, ...(await accounts.positions(acct.email)).map(p => p.memberId)].filter(Boolean);
const bal = await X.ads.balances(ids, acct.email);
if (bal.available > 0) {
// credits sit on positions and each campaign pays from one, so a pooled total alone misleads
// members with linked positions (Jim Watts, 2026-09-27: "561 unspent" but a top-up allowed 19)
const onPos = (bal.per || []).filter(p => p.avail > 0).sort((a, b) => b.avail - a.avail);
const loose = (bal.credited || 0) + (bal.earned || 0);
let where = '';
if (onPos.length > 1) where = ' They are spread across your positions: ' + onPos.map(p => '#' + p.memberId + ' has ' + p.avail.toLocaleString()).join(', ') + (loose ? ', plus ' + loose.toLocaleString() + ' that any position can use' : '') + '. Each campaign pays from one position, so start a new campaign from #' + onPos[0].memberId + ' to use the most in one go.';
parts.push('- You have ' + bal.available.toLocaleString() + ' ad credits sitting unspent. That is ' + bal.available.toLocaleString() + ' cents of delivery doing nothing.' + where + ' Campaigns > New campaign, point it at your invite link: https://instantadpay.com/my#campaigns');
}
else if (bal.inCampaigns > 0) parts.push('- All ' + bal.inCampaigns.toLocaleString() + ' of your credits are working in live campaigns. Good.');
} catch (e) {}
// streak
try {
const st = await X.ads.viewStatus(acct.email);
if (st.streakDay > 1) parts.push('- Your claim streak is on day ' + st.streakDay + '. Today\'s claim pays ' + (st.claimCredits || 0) + ' credits; miss a day and it restarts at 5.');
else parts.push('- Five ads and a claim a day is the free way in: 5, 7, 10, then 25 credits every seventh day in a row: https://instantadpay.com/my#earn');
} catch (e) {}
// contest
if (lbWeek && lbWeek.top) {
const me = lbWeek.top.find(r => r.name === '@' + acct.username) || null;
let mine = me; if (!mine) { try { mine = (await X.lb().view('week', acct.email)).me; } catch (e) {} }
parts.push('- Referral contest this week (' + (lbWeek.prize || 'credits to the top 3') + '): ' + (lbWeek.top.length ? lbWeek.top.slice(0, 3).map(r => r.rank + '. ' + r.name + ' (' + r.sales + ' sold)').join(', ') : 'no sales yet, first sale takes the top spot') + '.'
+ (mine ? ' You are #' + mine.rank + ' with ' + mine.sales + ' sold.' : ' You are not on the board yet; one $20 package bought by someone you sponsor puts you there.') + ' https://instantadpay.com/leaderboard');
}
// tank
if (tankN > 0 && acct.memberId) parts.push('- ' + tankN + ' member' + (tankN === 1 ? ' is' : 's are') + ' waiting for a sponsor in the holding tank. Adopt one from My line: https://instantadpay.com/my#line');
// line (sponsors only)
if (view.directs.length) {
const week = view.directs.filter(d => now - d.joined < 7 * DAY).length;
parts.push('- Your line: ' + view.directs.length + ' direct' + (view.directs.length === 1 ? '' : 's') + ', ' + week + ' joined this week, ' + view.stalled + ' gone quiet.');
const actions = view.directs.filter(d => d.stalled).slice(0, 3).map(d => ' Message ' + d.name + ': "' + d.say.replace('{{name}}', d.name.replace(/^@/, '')) + '"');
if (actions.length) parts.push(actions.join('\n'));
}
parts.push('\nTwenty minutes, in order: the set, one message to your line, the tank, one conversation outward. https://instantadpay.com/blog/the-twenty-minute-day\n\nInstantAdPay · https://instantadpay.com/my\nNo income is guaranteed. Credits are advertising, not money.');
const subject = lbWeek && lbWeek.top && lbWeek.top.length && lbWeek.top[0].name === '@' + acct.username ? 'You are #1 this week on InstantAdPay' : 'Your week on InstantAdPay: credits, streak, contest';
try { await mailer.send(acct.email, subject, parts.join('\n')); digests += 1; } catch (e) { console.error('digest', acct.email, e.message); }
const { subject, text, html } = await weeklyDigest(acct, view, lbWeek, tankN, now);
try { await mailer.send(acct.email, subject, text, html); digests += 1; } catch (e) { console.error('digest', acct.email, e.message); }
await impl().setDigest(acct.email, now);
if (digests >= 30) break;
}
@@ -297,4 +354,4 @@ function init(opts) { X = arguments[0] || {};
J.load();
}
async function viewsSince(since) { return impl().viewsSince(since); }
module.exports = { init, RUNGS, rungFor, describe, coachView, prospects, saveProspect, removeProspect, STATUSES, recordView, linkStats, nudgeTick, recordClick, clickSources, refHost, viewsSince };
module.exports = { init, weeklyDigest, RUNGS, rungFor, describe, coachView, prospects, saveProspect, removeProspect, STATUSES, recordView, linkStats, nudgeTick, recordClick, clickSources, refHost, viewsSince };
+4 -2
View File
@@ -15,13 +15,15 @@ function key() {
}
function hasKey() { return !!key(); }
function send(to, subject, text) {
function send(to, subject, text, html) { // html optional (2026-10-01): sent alongside the plain text, never instead of it
return new Promise((resolve, reject) => {
const content = [{ type: 'text/plain', value: text }];
if (html) content.push({ type: 'text/html', value: html });
const body = JSON.stringify({
personalizations: [{ to: [{ email: to }] }],
from: FROM,
subject,
content: [{ type: 'text/plain', value: text }]
content
});
const req = https.request({ hostname: 'api.sendgrid.com', path: '/v3/mail/send', method: 'POST',
headers: { Authorization: 'Bearer ' + key(), 'Content-Type': 'application/json',
+7 -1
View File
@@ -62,4 +62,10 @@ async function sync() {
return t;
}
function status() { return { enabled: enabled(), bridge: enabled() ? process.env.PD_BRIDGE_URL.replace(/\?.*$/, '') : null, last: S.last, tracked: Object.keys(S.served).length }; }
module.exports = { enabled, init, sync, status, listing };
// the member's own PassiveDrip line for the Games card (2026-10-01): bridge action 'member', read only
async function member(memberId, email) {
if (!enabled()) return null;
const j = await bridge('member', 'POST', { memberId: Number(memberId) || 0, email: String(email || '').toLowerCase() });
return j && j.ok ? j : null;
}
module.exports = { enabled, init, sync, status, listing, member };
+2 -1
View File
@@ -823,6 +823,7 @@
}
// came from a Drip Runner share link: once they have a username, straight back into the game (2026-09-30)
if (me.returnTo === 'driprunner' && !render.toGame) { render.toGame = true; location.href = '/api/my/driprunner'; return; }
if (me.returnTo === 'passivedrip' && !render.toGame) { render.toGame = true; location.href = '/api/my/passivedrip'; return; } // PassiveDrip sent them here to sign in (2026-10-01)
// arrived from an invite page: run the welcome tour and login ad once
if (/[?&]welcome=1/.test(location.search) && !render.welcomed) {
render.welcomed = true;
@@ -1643,7 +1644,7 @@
let g = null; try { g = await (await fetch('/api/my/games')).json(); } catch (e) {}
const list = (g && g.games) || [];
if (!list.length) { el.innerHTML = '<p class="muted small">No games are open yet. Check back soon.</p>'; return; }
el.innerHTML = list.map(x => '<div class="game-card"><img src="' + esc(x.art) + '" alt="" loading="lazy"><div class="gc-body"><span class="gc-tag">' + esc(x.tag || '') + '</span><h4>' + esc(x.name) + (x.preview ? '<span class="gc-pre">preview, not live</span>' : '') + '</h4><p class="muted small" style="margin:0">' + esc(x.blurb) + '</p>' + (x.progress && x.progress.line ? '<div class="gc-prog">' + esc(x.progress.line) + '</div>' : '') + '<p class="muted small" style="margin:0">Pays: ' + esc(x.pays || 'POL') + '</p><a class="btn" href="' + esc(x.play) + '">Play</a></div></div>').join('');
el.innerHTML = list.map(x => '<div class="game-card"><img src="' + esc(x.art) + '" alt="" loading="lazy"><div class="gc-body"><span class="gc-tag">' + esc(x.tag || '') + '</span><h4>' + esc(x.name) + (x.preview ? '<span class="gc-pre">preview, not live</span>' : '') + '</h4><p class="muted small" style="margin:0">' + esc(x.blurb) + '</p>' + (x.progress && x.progress.line ? '<div class="gc-prog">' + esc(x.progress.line) + '</div>' : '') + '<p class="muted small" style="margin:0">Pays: ' + esc(x.pays || 'POL') + '</p><a class="btn" href="' + esc(x.play) + '">' + esc(x.cta || 'Play') + '</a></div></div>').join('');
}
async function loadReturnCard() {
const card = $('phReturn'); if (!card) return;
+17
View File
@@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 420" role="img" aria-label="PassiveDrip">
<defs>
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#1b1446"/><stop offset="1" stop-color="#4c1d95"/></linearGradient>
<radialGradient id="coin" cx=".35" cy=".3" r=".8"><stop offset="0" stop-color="#c4a6ff"/><stop offset=".6" stop-color="#8247e5"/><stop offset="1" stop-color="#4b1fa8"/></radialGradient>
<linearGradient id="drop" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#9fd8ff"/><stop offset="1" stop-color="#3b82f6"/></linearGradient>
</defs>
<rect width="800" height="420" fill="url(#bg)"/>
<g opacity=".18" fill="#ffffff"><circle cx="90" cy="70" r="3"/><circle cx="700" cy="60" r="4"/><circle cx="640" cy="350" r="3"/><circle cx="160" cy="360" r="4"/><circle cx="420" cy="40" r="2"/></g>
<path d="M400 60 C400 60 340 140 340 180 a60 60 0 0 0 120 0 C460 140 400 60 400 60 Z" fill="url(#drop)"/>
<g transform="translate(400 300)">
<ellipse cx="0" cy="34" rx="92" ry="16" fill="#000" opacity=".25"/>
<circle r="78" fill="url(#coin)" stroke="#d8c7ff" stroke-width="5"/>
<path d="M-28 -24 l28 -16 l28 16 v32 l-28 16 l-28 -16 Z" fill="none" stroke="#ffffff" stroke-width="8" stroke-linejoin="round"/>
</g>
<text x="40" y="220" font-family="Arial, Helvetica, sans-serif" font-size="44" font-weight="800" fill="#ffffff">PassiveDrip</text>
<text x="42" y="256" font-family="Arial, Helvetica, sans-serif" font-size="20" fill="#d8c7ff">Faucet + games, paid in POL</text>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

+1 -1
View File
@@ -1099,7 +1099,7 @@
<script src="/assets/common.js?v=20260929b"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/wallet.js?v=20260911a"></script>
<script src="/assets/promo.js?v=20260929c"></script>
<script src="/assets/my.js?v=20261001a"></script>
<script src="/assets/my.js?v=20261001b"></script>
<script src="/assets/chat.js?v=20260907l"></script>
</body>
</html>
+29 -3
View File
@@ -1255,8 +1255,22 @@ function GAMES() {
art: DR_URL() + '/badges/ch5.jpg', play: '/api/my/driprunner', pays: 'POL to your wallet at 0.25', progress: drProgress },
{ slug: 'polhunter', name: 'PolHunter', tag: 'Scavenger hunt', blurb: 'Hunt hidden codes on sites across the network. Every find drips POL straight to your wallet.',
art: 'https://polhunter.com/img/hero-800.webp', play: '/api/my/polhunter', pays: 'POL per find' },
{ slug: 'passivedrip', name: 'PassiveDrip', tag: 'Faucet + games', blurb: 'Claim the faucet, view paid-to-click ads, roll the bonus and play the mini games for coins. One tap signs you in with this account, no new password.',
art: '/assets/passivedrip-card.svg', play: '/api/my/passivedrip', cta: 'Open', pays: 'POL to your wallet at 2,000 coins ($1)', progress: pdProgress },
];
}
// -- PassiveDrip hand-off (2026-10-01): same token shape as Drip Runner, its own secret (PD_SSO_SECRET, also stored in
// PassiveDrip's site_config iap_sso_secret). PassiveDrip signs the member in or creates the account, carries the sponsor
// over by email, and OFFERS the wallet with one confirm tap; it never writes or overwrites a payout address silently.
const PD_SECRET = () => String(process.env.PD_SSO_SECRET || '').trim();
const PD_URL = () => String(process.env.PD_URL || 'https://passivedrip.com').replace(/\/+$/, '');
function pdMint(claims) { const payload = JSON.stringify(Object.assign({ aud: 'passivedrip', iat: Date.now(), exp: Date.now() + 5 * 60000, nonce: crypto.randomBytes(16).toString('hex') }, claims)); return drB64u(payload) + '.' + drB64u(crypto.createHmac('sha256', PD_SECRET()).update(payload).digest()); }
async function pdProgress(memberId, email) {
const j = await pdsync.member(memberId, email); if (!j) return null;
if (!j.exists) return { line: 'No PassiveDrip account yet. Open it and one is made for you.' };
const coins = Math.floor(Number(j.coins) || 0);
return { line: '@' + j.username + ' · ' + coins.toLocaleString('en-US') + ' of ' + Number(j.threshold || 2000).toLocaleString('en-US') + ' coins' + (j.hasWallet ? '' : ' · no payout wallet yet') + (j.paidPol ? ' · ' + Number(j.paidPol).toFixed(2) + ' POL paid out' : '') };
}
// the player's own line on the Drip Runner card, read from the game with a signed request
async function drProgress(memberId) {
if (DR_SECRET().length < 32) return null;
@@ -1636,7 +1650,7 @@ const server = http.createServer(async (req, res) => {
let memberId = 0;
if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} }
const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId });
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: parseCookies(req)['iap.return'] === 'driprunner' ? '/api/my/driprunner' : null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
}
// -- wallet auth: link-to-account when an email session exists, or
@@ -1715,7 +1729,7 @@ const server = http.createServer(async (req, res) => {
const _defSpon = Number(siteConfig().defaultSponsorId) || 1;
if (!sponsorId && memberId !== _defSpon) sponsorId = _defSpon; // orphan fallback → #1 (never self-sponsor)
if (memberId && acct && acct.memberId !== memberId) accounts.setMemberId(acct.email, memberId).catch(() => {});
const out = { signedIn: true, returnTo: ['polhunter', 'driprunner'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
const out = { signedIn: true, returnTo: ['polhunter', 'driprunner', 'passivedrip'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
address: s.address || (acct && acct.address) || null, memberId,
username: (acct && acct.username) || null,
refCode: (acct && acct.code) || null, sponsorId,
@@ -2455,6 +2469,18 @@ const server = http.createServer(async (req, res) => {
sponsorRef: (acct && acct.sponsorRef) || null, joinedRef: (acct && acct.joinedRef) || null, joinedAt: (acct && acct.created) || null }); // the game credits referrals to the IAP sponsor
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
}
// -- PassiveDrip hand-off (2026-10-01): sign the member across; PassiveDrip verifies with the shared secret.
// wallet = the signature-verified main wallet (accounts.linkWallet runs only after /api/auth/verify), offered there, never imposed.
if (p === '/api/my/passivedrip' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Set-Cookie': 'iap.return=passivedrip; Path=/; SameSite=Lax; Max-Age=1800' + (IS_PROD ? '; Secure' : ''), 'Cache-Control': 'no-store' }); return res.end(); } // sign in first, then straight across
if (PD_SECRET().length < 32) return json(res, 503, { error: 'PassiveDrip is not connected yet.' });
const acct = await accounts.byEmail(s.email);
const memberId = (acct && acct.memberId) || s.memberId || 0;
let sponsorEmail = null; try { const up = await uplineSlides(s.email, 1); sponsorEmail = (up[0] && up[0].email) || null; } catch (e) {}
const tok = pdMint({ memberId: Number(memberId), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null, sponsorEmail });
res.writeHead(302, { Location: PD_URL() + '/iap-signin.php?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
}
// -- Drip Runner refuel: a real verified visit (advertiser charged as usual); the player gets fuel, not credits
if (p === '/api/refuel/open' && req.method === 'GET') {
const r = drOpen(u.searchParams.get('t')); if (r.error) return json(res, 400, { error: r.error });
@@ -2521,7 +2547,7 @@ const server = http.createServer(async (req, res) => {
for (const g of GAMES()) {
const isLive = live.has(g.slug); if (!isLive && !admin) continue;
const card = Object.assign({}, g, { live: isLive, preview: !isLive });
if (g.progress && memberId) { try { card.progress = await g.progress(memberId); } catch (e) {} }
if (g.progress && (memberId || g.slug === 'passivedrip')) { try { card.progress = await g.progress(memberId, s.email); } catch (e) {} }
out.push(card);
}
return json(res, 200, { games: out.map(g => { const c = Object.assign({}, g); if (typeof c.progress === 'function') delete c.progress; return c; }) });