Admin: grant Stack POL Pro for a $10+ package bought without a Pro order first (Marty 2026-11-09, Orlando). POST /api/admin/stackpro/grant {memberId, tx}: the tx must be an on-chain Purchase of $10+ by that member; recorded as a package sale with its tx, marks the Stack POL page Pro and posts the badge once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-09 16:30:34 -06:00
parent 054ce10985
commit 1da37f05ab
2 changed files with 23 additions and 1 deletions
+10 -1
View File
@@ -278,6 +278,15 @@ function buyStackPro(email, now) {
}
function cancelStackOrder(email) { const e = String(email || '').toLowerCase(); const w = stackOrders(e)[0]; if (!w) return { ok: true }; orders.set(w.order, Object.assign({}, orders.get(w.order), { status: 'cancelled', cancelledAt: Date.now() })); return { ok: true, order: w.order }; }
function compStackPro(email, on, note) { const e = String(email || '').toLowerCase(); if (on) stackpro.set(e, { ts: Date.now(), via: 'comp', note: String(note || '').slice(0, 120) }); else stackpro.delete(e); return { ok: true, pro: !!on }; }
// a package bought WITHOUT a Pro order first, granted by the admin (Marty 2026-11-09, Orlando's $10 package): recorded as a
// package sale with its tx so it counts as new money, and the tx is marked used like any fulfilment
function grantStackProForPackage(email, tx, cents, buyerId, note) {
const e = String(email || '').toLowerCase(); if (!e) return { error: 'No account.' };
if (stackpro.get(e)) return { ok: true, already: true };
stackpro.set(e, { ts: Date.now(), via: 'package', tx, cents, buyerId, note: String(note || 'admin grant: package bought without a Pro order').slice(0, 120) });
console.log('stack pro granted for package', e, tx, cents, 'cents');
return { ok: true, pro: true };
}
function stackProOwners() { return [...stackpro.keys()]; }
// A package purchase landing on chain fulfils one of this account's waiting orders: the highest-priced one the package covers.
@@ -672,5 +681,5 @@ function prune(now) {
return n;
}
module.exports = { STACK_PRO_CENTS, stackPro, stackProView, buyStackPro, cancelStackOrder, compStackPro, stackProOwners, init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, HERO_DEFS, HERO_KEYS, heroesOwned, heroClaim, heroView, buyHero, cancelHeroOrder, compHero, revokeHero, heroStats, flag, activity, view, buy, cancelOrder, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey,
module.exports = { STACK_PRO_CENTS, stackPro, stackProView, buyStackPro, cancelStackOrder, compStackPro, stackProOwners, grantStackProForPackage, init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, HERO_DEFS, HERO_KEYS, heroesOwned, heroClaim, heroView, buyHero, cancelHeroOrder, compHero, revokeHero, heroStats, flag, activity, view, buy, cancelOrder, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey,
_ledger: () => L };
+13
View File
@@ -4530,6 +4530,19 @@ const server = http.createServer(async (req, res) => {
if (!r.error) console.log('bonus heroes admin test', p.split('/').pop(), hero, me);
return json(res, r.error ? 400 : 200, Object.assign({ email: me, test: true, heroes: gamepass.heroView(me, Date.now(), { preview: true }) }, r));
}
// Admin: give Stack POL Pro for a package that was bought without a Pro order first (Marty 2026-11-09). The tx must be an on-chain
// Purchase of $10 or more by that member id; then the badge posts like any unlock.
if (p === '/api/admin/stackpro/grant' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const id = Number(b.memberId), tx = String(b.tx || '').toLowerCase();
let ev = null; try { ev = (JSON.parse(fs.readFileSync(path.join(DATA_DIR, 'chain-index.json'), 'utf8')).events || []).find(e => e.type === 'Purchase' && String(e.tx || '').toLowerCase() === tx); } catch (e) {}
if (!ev || Number(ev.buyerId) !== id || Number(ev.priceCents) < gamepass.STACK_PRO_CENTS) return json(res, 400, { error: 'That tx is not a $10+ package bought by member #' + id + '.', ev });
const a = await accounts.byMemberId(id); if (!a || !a.email) return json(res, 404, { error: 'No account for member #' + id });
const r = gamepass.grantStackProForPackage(a.email, tx, Number(ev.priceCents), id, b.note);
try { await stackProMark(a.email); } catch (e) {}
let posted = 0; try { posted = await postBadgeOnce(a.email, 'stackpro'); } catch (e) { console.error('stackpro badge', e.message); }
return json(res, 200, Object.assign({ username: a.username, posted }, r));
}
if (p === '/api/admin/heroes/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.heroStats()); }
// Admin > Game Pass tier test (2026-10-25, Marty): every tier as members will see it, with the admin's OWN account's state, and a
// test buy of a tier that is not on sale yet (opens the same waiting order a member gets; a fresh package on /my fulfils it).