Holding tank: 24-hour sign-up grace plus a Who invited you card (Marty 2026-11-07: "24-hour grace plus the prompt"). On Nov 2 a sponsorless sign-up was adopted five hours after joining, before he could say who invited him.

Grace: for 24 hours from an account's created time nobody can adopt the person by hand. They stay on the waiting list after the open ones with an Opens in badge and no Adopt button, and adopt() refuses in plain words. Only sign-up counts, so someone back in the tank later has no grace. Auto-assign does not wait for it: the 24-hour hold still runs from the wallet link and is not stretched. No notice tells people to adopt someone they cannot adopt yet: the wallet-ready post waits for the grace and says the time really left, is skipped when the rotation takes them in that tick, the arrivals post moves to when the grace ends (marks.claim per member), and the Overview note and weekly email count only people who are open.

Prompt: a member with no sponsor and no member number sees the card at the top of Overview, types a username, confirms in an in-page box, and that person becomes their sponsor through setSponsor as a deliberate change with by 'invited', so it follows to LinkSpin and clears the hold. Refused: self, unknown username, already sponsored, member number or wallet already on the contract, a chain loop, a suspended sponsor, a no-payout chain, and a line with nobody on the contract (they would walk up to the company). The network sponsor is tried first. Nobody invited me hides it and a small link brings it back. Not an adoption: status 'invited', no 7-day window, not counted toward the two. The named sponsor gets the referral email and an on-site notice. Switch-on-payouts reminders track the named sponsor.

Chatbot canned + systemPrompt, KNOWLEDGE_DATE 2026-11-07. my.js, admin.js, admin-sponsorcheck.js ?v=20261107tg. qa/tank-hold.mjs, qa/sponsorfollow.test.cjs and qa/sponsorfollow-e2e.mjs extended (SF_E2E_PORT overrides the ports).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-07 07:04:18 -06:00
parent 973fc80570
commit bfbea142b6
13 changed files with 405 additions and 33 deletions
+96 -9
View File
@@ -16,11 +16,15 @@ const TTL_MS = 7 * 86400000; // an adoption's window to convert
const MAX_ADOPTIONS = 2; // per adoptee, lifetime (dropped adoptions count too, since 2026-09-13)
const HOLD_MS = 3 * 24 * 3600 * 1000; // an adoption is a commitment: no releasing someone you picked up less than 3 days ago (Marty, 2026-09-13)
// statuses that do not count toward a person's two adoptions: a release record, and the later side of a network race
// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js)
const NOT_COUNTED = ['released', 'conflict'];
// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js), and a record of a
// member naming who invited them (nobody adopted them; nameSponsor below)
const NOT_COUNTED = ['released', 'conflict', 'invited'];
const MIN_OWN_BUY_CENTS = 2000; // adopter must have bought a $20+ package themselves
const WARN_DAYS = 10; // dormant lead: sponsor warned after this many days without contact
const RESCUE_DAYS = 14; // ...and the lead moves to the tank after this many (warning at least 4 days old)
const GRACE_MS = 24 * 3600 * 1000; // nobody adopts a new sign-up by hand for this long after `created`, so they can say who invited them (Marty 2026-11-07)
const BRAND = 'InstantAdPay';
const LINE_URL = () => siteUrl + '/my#line';
let DATA_DIR = '.', accounts, chain, messages, mailer, siteUrl = 'https://instantadpay.com';
@@ -48,10 +52,10 @@ const D = {
const rows = adopter ? await db.q("SELECT * FROM adoptions WHERE status='open' AND adopter=?", [adopter]) : await db.q("SELECT * FROM adoptions WHERE status='open'");
return rows.map(rowA);
},
async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n); },
async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n); },
async setStatus(id, status) { await db.q('UPDATE adoptions SET status=?, closed=? WHERE id=?', [status, Date.now(), Number(id)]); },
async recent(n) { return (await db.q('SELECT * FROM adoptions ORDER BY id DESC LIMIT ?', [Number(n) || 100])).map(rowA); },
async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n) > 0; },
async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n) > 0; },
async all() { return (await db.q('SELECT * FROM adoptions ORDER BY id')).map(rowA); },
async mark(lead) { const r = await db.q('SELECT * FROM lead_marks WHERE `lead`=?', [lead]); return r[0] ? { sponsor: r[0].sponsor, contacted: Number(r[0].contacted_ts || 0), warned: Number(r[0].warned_ts || 0) } : null; },
async setMark(lead, f) {
@@ -88,9 +92,10 @@ async function waiting() {
wallet: !!a.address, activated: !!a.memberId, // in the tank "activated" is always false (payouts on = out of the tank); wallet can still be linked
earned: (tot[a.email] || {}).earned || 0, balance: (tot[a.email] || {}).balance || 0,
// wallet linked = ready to switch on payouts, held for an adopter (24-hour clock, autoAssign after that)
opensAt: inGrace(a) ? graceEnd(a) : 0, // new sign-up: nobody can adopt them by hand before this (0 = open now)
...(() => { const r = a.address ? readyRec(a.email) : null; return r ? { ready: true, readyAt: r.readyAt, holdUntil: r.readyAt + READY_MS } : { ready: false }; })() }))
// ready members first (least time left first), then newest sign-in
.sort((a, b) => (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined));
// open before the sign-up grace ones, ready members first (least time left first), then newest sign-in
.sort((a, b) => (a.opensAt ? 1 : 0) - (b.opensAt ? 1 : 0) || (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined));
}
// has this member bought a $20+ package themselves? (the qualifying-for-yourself buy)
@@ -117,7 +122,7 @@ async function view(email) {
const a = await accounts.byEmail(ad.adoptee);
mine.push({ id: ad.id, name: a ? nameOf(a) : mask(ad.adoptee), email: ad.adoptee, ts: ad.ts, expires: ad.expires, lastSeen: a ? (a.lastSeen || 0) : 0, wallet: !!(a && a.address), address: (a && a.address) || null, bought: !!(a && a.memberId) });
}
return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, waiting: await waiting(), mine };
return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, graceHours: GRACE_MS / 3600000, waiting: await waiting(), mine };
}
async function adopt(adopterEmail, who, note, opts) {
@@ -131,6 +136,7 @@ async function adopt(adopterEmail, who, note, opts) {
const target = list.find(w => (w.username && w.username.toLowerCase() === key) || w.email === key);
if (!target) return { error: 'That member is no longer in the tank.' };
if (target.email === e) return { error: 'That is you.' };
if (!auto && target.opensAt > clock()) return { error: 'That member joined less than 24 hours ago, so they still have time to tell us who invited them. You can adopt them in ' + leftText(target.opensAt - clock()) + '.' }; // the safety net is not held by this: it keeps its 24-hour clock from the wallet link
if (remoteOpen(target.email)) return { error: 'That member was just picked up on ' + OTHER + ', so they are no longer in the tank.' };
if (!auto && await countAll(target.email) >= MAX_ADOPTIONS) return { error: 'That member has been adopted twice already and stays where they are.' }; // the safety net never leaves anyone to the company
const token = me.username || me.code || String(me.memberId);
@@ -477,7 +483,9 @@ async function readyTick() {
// linkedNow: the member was on the site when they became ready, so they linked the wallet just now; otherwise the
// wallet predates this tank visit (e.g. a dormant member returned by a sponsor; Marty 2026-10-29: the notice read as a
// fresh link) and the notice says so, with their last sign-in
if (rec && !rec.notified) { rec.notified = clock(); fresh.push({ email: a.email, name: nameOf(a), username: a.username || null, until: rec.readyAt + READY_MS, lastSeen: a.lastSeen || 0, linkedNow: (a.lastSeen || 0) >= rec.readyAt - 15 * 60 * 1000 }); }
// Sign-up grace (2026-11-07): no "adopt them" post for someone who cannot be adopted yet; announced when the grace ends,
// and not at all when the safety net takes them in this same tick (nothing left for anyone to do)
if (rec && !rec.notified && !inGrace(a)) { rec.notified = clock(); if (clock() < rec.readyAt + READY_MS - TICK_MS) fresh.push({ email: a.email, name: nameOf(a), username: a.username || null, until: rec.readyAt + READY_MS, lastSeen: a.lastSeen || 0, linkedNow: (a.lastSeen || 0) >= rec.readyAt - 15 * 60 * 1000 }); }
}
RS.save();
const auto = await autoAssign();
@@ -548,6 +556,85 @@ async function payTick() {
function payView() { return Object.entries(RS.load().pay || {}).map(([email, r]) => Object.assign({ email }, r)).sort((x, y) => y.at - x.at).slice(0, 100); }
function alignedRecent(n) { return RS.load().aligned.slice(-(n || 50)).reverse(); }
// ── sign-up grace + "Who invited you?" (Marty approved 2026-11-07: "24-hour grace plus the prompt") ──
// Nov 2: @santoridaviss signed up with no referral at 10:35 PM, was adoptable at 2:24 AM and adopted at 3:36 AM, before he
// could say who invited him. So:
// GRACE: for 24 hours from the account's `created`, nobody can adopt the person BY HAND. They stay on the waiting list with
// opensAt set (the card shows "Opens in ...", no Adopt button). The dates are each site's own account dates. Only sign-up
// counts: someone back in the tank later (released, rescued, window ended) is past it.
// The safety net does not wait for the grace (opts.auto skips it): Marty's rule is a wallet-linked member is held for no
// longer than 24 hours, so autoAssign keeps its clock from the wallet link. Wallet linked in the first 15 minutes: the
// rotation can fire up to 15 minutes before the grace ends, and hand adoption never opens for them. Wallet linked in the
// first hour: hand adoption opens at 24 hours and the rotation takes them about an hour after that.
// Notices: readyTick announces a ready member only once they can be adopted, and only when time is left (adoptableOf and
// openedSince keep the Overview note, the arrivals post and the weekly email to people who are open too).
// PROMPT: a tank member can name who invited them. nameSponsor() goes through setSponsor like adopt(), so it follows to the
// other site and clears the hold the same way, but it is the member's own choice: only ever for the signed-in member,
// never an open adoption (no 7-day window, no fall-back, no count toward the two), recorded as status 'invited'.
function graceEnd(a) { return (Number(a && a.created) || 0) + GRACE_MS; }
function inGrace(a) { return graceEnd(a) > clock(); }
function leftText(ms) { const m = Math.max(1, Math.ceil(Number(ms) / 60000) || 1); const h = Math.floor(m / 60); return h ? h + ' h ' + (m % 60) + ' min' : m + ' min'; }
const adoptableOf = list => (list || []).filter(w => !(w.opensAt > clock()));
async function adoptable() { return adoptableOf(await waiting()); }
// people whose grace ended after `since` (the arrivals post: announced when they can be adopted, not when they sign up)
function openedSince(list, since) { const now = clock(); return (list || []).filter(w => { const t = (Number(w.joined) || 0) + GRACE_MS; return t > since && t <= now; }); }
// what the dashboard needs: null = no card. dismissed = they tapped "Nobody invited me" (a small link brings the card back).
function inviteAsk(a) {
if (!a || !inTank(a) || remoteOpen(a.email)) return null;
return { dismissed: !!(RS.load().noInvite || {})[String(a.email || '').toLowerCase()] };
}
function dismissInvite(email) { const st = RS.load(); st.noInvite = st.noInvite || {}; st.noInvite[String(email || '').toLowerCase()] = clock(); RS.save(); return { ok: true }; }
// someone in the named person's line (them first) already has a contract position? Otherwise the member would be walked up to
// the company at their first activation, the one thing the tank exists to stop
async function firstOnContract(sp) {
let cur = sp; const seen = new Set();
for (let i = 0; cur && i < 60; i++) { if (Number(cur.memberId) > 0) return cur; if (seen.has(cur.email)) return null; seen.add(cur.email); cur = await accounts.sponsorOf(cur.email); }
return null;
}
// opts.check: every refusal, nothing written (the card asks "is this them?" before the real call)
async function nameSponsor(email, who, opts) {
const e = String(email || '').toLowerCase(); const check = !!(opts && opts.check);
const LOCKED = 'Your payouts are already on, so your sponsor is locked on the contract.';
let a = await accounts.byEmail(e);
if (!a) return { error: 'Sign in first.' };
if (Number(a.memberId) > 0) return { error: LOCKED };
if (a.sponsorRef) return { error: 'You already have a sponsor.' };
if (a.address) { // wallet on the contract already, member number not saved yet
if (hooks.bound) { const id = await Promise.resolve(hooks.bound(a)).catch(() => -1); if (id < 0) return { error: 'Could not check the contract just now. Try again in a minute.' }; if (id > 0) return { error: LOCKED }; }
else if (hooks.activated && await Promise.resolve(hooks.activated(a)).catch(() => false)) return { error: LOCKED };
}
if (remoteOpen(e)) return { error: 'You were just picked up on ' + OTHER + ', so you already have a sponsor.' };
const al = await alignToNetwork(a).catch(() => null); // one identity: the sponsor the network already knows comes first
if (al) return { error: 'You already have a sponsor on the network: ' + al.toName + '.', aligned: true };
const key = String(who || '').trim().toLowerCase().replace(/^@+/, '');
if (!key) return { error: 'Type the username of the person who invited you.' };
const sp = /^[a-z0-9_]{3,20}$/.test(key) ? await accounts.byUsername(key) : null;
if (!sp || (accounts.isUnclaimedShell && accounts.isUnclaimedShell(sp))) return { error: 'No member here has the username ' + key + '. Check the spelling with the person who invited you.' };
if (String(sp.email).toLowerCase() === e) return { error: 'That is you. Type the username of the person who invited you.' };
const bar = hooks.excluded || hooks.isSuspended;
if (bar && bar(sp.email)) return { error: nameOf(sp) + ' cannot take new members right now.' };
if (await inDownlineOf(e, sp)) return { error: nameOf(sp) + ' is in your own line, so they cannot be your sponsor.' };
const payee = await firstOnContract(sp);
if (!payee) return { error: nameOf(sp) + ' has not switched on payouts yet, and nobody above them has either, so you cannot go under them yet. Ask them to switch on payouts, then come back here.' };
if (hooks.payoutBlocked && await Promise.resolve(hooks.payoutBlocked(Number(payee.memberId))).catch(() => true)) return { error: nameOf(sp) + ' cannot take new members right now.' };
if (check) return { ok: true, check: true, name: nameOf(sp) };
a = await accounts.byEmail(e);
if (!a || !inTank(a)) return { error: 'You already have a sponsor.' };
const token = sp.username || sp.code || String(sp.memberId);
const r = await setSponsor(e, token, 'invited', 'named by the member on the Who invited you card');
if (r && r.error) return r;
const now = clock();
const ad = await impl().add({ adoptee: e, adopter: String(sp.email).toLowerCase(), ts: now, expires: now, status: 'invited', note: 'named by the member on the Who invited you card' });
{ const rr = RS.load().ready[e]; if (rr && !rr.done) { rr.done = now; rr.namedSponsor = sp.email; RS.save(); } } // the hold lifts: their sponsor resolves now
const name = nameOf(a);
payTrack(e, sp.email, ad.id, false); // the same switch-on-payouts reminders as an adoption (payTick)
const subject = 'You have a new referral on ' + BRAND;
const text = name + ' joined ' + BRAND + ' without a sponsor link and told us you invited them, so they are on your team from today. Say hello and help them with their first steps: ' + LINE_URL();
if (mailer && mailer.hasKey()) { try { await mailer.send(sp.email, subject, text + '\n\n' + BRAND); } catch (err) {} }
if (hooks.notify) { try { await hooks.notify(sp.email, subject, text); } catch (err) {} }
return { ok: true, name: nameOf(sp), sponsorEmail: sp.email, member: name };
}
async function adminView() {
const recent = await impl().recent(200);
const names = {};
@@ -555,4 +642,4 @@ async function adminView() {
return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30), payReminders: payView() };
}
module.exports = { init, view, adopt, holdFor, markReady, readyRec, readyTick, autoAssign, payTick, payView, activateLink, PAY_R1_MS, PAY_R2_MS, alignToNetwork, alignedRecent, setClock, eligibility, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };
module.exports = { init, view, adopt, holdFor, markReady, readyRec, readyTick, autoAssign, payTick, payView, activateLink, PAY_R1_MS, PAY_R2_MS, alignToNetwork, alignedRecent, setClock, eligibility, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, adoptable, adoptableOf, openedSince, leftText, inviteAsk, dismissInvite, nameSponsor, GRACE_MS, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };