Game Pass tier testing moves to Admin > Game Pass (Marty 2026-10-25): the member Games card shows every account, the admin's included, exactly what a member sees (weekly pass only while sovTiers is off; a holder sees the tier they hold). The /my admin preview note and the admin bypass on GET /api/my/gamepass and POST /api/my/gamepass/buy are gone. New Admin > Game Pass > Tier test and preview card (labelled TEST / PREVIEW): all five tiers as members will see them with on-sale/hidden chips and the admin's own status, Test buy (real waiting order fulfilled by a fresh package), Cancel test order, Give my account (test comp, no sale), End. New admin-only routes GET /api/admin/gamepass/preview, POST /api/admin/gamepass/test-buy | test-cancel | test-comp, always on the signed-in admin's own account. sovTiers untouched. QA: sov-passes-local + store reworked to the new flow (all pass); my.js and admin.js ?v= bumped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-25 08:37:17 -05:00
parent cecba6b313
commit 7f80d82486
9 changed files with 164 additions and 48 deletions
+3 -1
View File
@@ -243,7 +243,9 @@ switched off for members (`sovTiers` 0) until Marty flips it.
keys). The hand-off token carries `gamePass: { active, until, tier }`; `GET /api/partner/player` carries
`pass: { active, until, tier, tiers }`, so Shards of Valor sees `sovereign` / `legend`.
- **Buy**: `POST /api/my/gamepass/buy { tier }` (missing = weekly). Every tier above weekly needs `sovTiers` on (and the weekly pass
on); while off, only the `ADMIN_EMAIL` account sees and can buy them (admin preview on the card). Short of purchased credits: a
on); while off, nobody sees or buys them on /my, the admin included (2026-10-25: the member card shows every account the
member view). The admin tests them in Admin > Game Pass > Tier test and preview (`GET /api/admin/gamepass/preview`, `POST
/api/admin/gamepass/test-buy | test-cancel | test-comp { tier }`, always the signed-in admin's own account). Short of purchased credits: a
waiting order per tier; a package of at least the tier price fulfils the highest-priced order it covers (one pass per purchase,
each tx once). Copy names the package that covers the price: $20 (Explorer), $50 (Champion, there is no $40 one), $100
(Sovereign), $250 (Legend).
+18 -10
View File
@@ -18,7 +18,7 @@
// nothing else changes). Tiers run side by side, each with its own expiry: record.tiers = { weekly: { until }, explorer: { until },
// champion: { until } }; the legacy `until` keeps mirroring the weekly tier (lazy migration: a record with no `tiers` reads its
// `until` as the weekly tier). flag().tier = the highest active tier. Explorer/Champion sales sit behind the site switch
// `sovTiers` (default off; only ADMIN_EMAIL can see and buy them while it is off). No proration, no auto-renew: buying again
// `sovTiers` (default off; while it is off the admin tests them from Admin > Game Pass, never on the member card). No proration, no auto-renew: buying again
// extends that tier from max(now, until).
// 2026-10-22 (Marty): every pass rides the package rail so sponsors get paid. Buying a pass never spends a credit balance any more
// (today's buyer paid from an old balance, so no new money came in and nobody upline was paid). A pass click opens an order; the
@@ -162,6 +162,11 @@ function extend(e, via, extra, now, tier) {
}
function waitingOrders(e) { const out = []; for (const [k, o] of orders) if (o.status === 'waiting' && o.email === e) out.push(Object.assign({ order: k }, o, { tier: tierOk(o.tier) ? o.tier : 'weekly' })); return out; }
function waitingOrder(e, tier) { return waitingOrders(e).find(o => o.tier === (tier || 'weekly')) || null; }
// the admin's tier test: drop a waiting order that was opened for testing, so a later real package never fulfils it by surprise
function cancelOrder(email, tier) {
const e = String(email || '').toLowerCase(); const w = waitingOrder(e, tier || 'weekly'); if (!w) return { ok: true, none: true };
orders.set(w.order, Object.assign({}, orders.get(w.order), { status: 'cancelled', cancelledAt: Date.now() })); return { ok: true, order: w.order, tier: w.tier };
}
function comp(email, why, tier, now) { // support comp: counts as no sale
const e = String(email || '').toLowerCase(); const x = extend(e, 'admin', { note: why || 'support', usd: 0 }, now, tier);
return { active: true, until: x.until, days: x.days, tier: x.tier };
@@ -175,21 +180,23 @@ function revoke(email, tier, why, now) {
passes.set(e, writeTiers(p, T, { revokes: [{ ts: t, tier, why: String(why || 'support').slice(0, 80), was }].concat(p.revokes || []).slice(0, 50) }));
return { ok: true, tier, was, until: t };
}
// on sale for this viewer: the tier's own switch, or the admin account testing the tiers above weekly while sovTiers is off
const tierOpen = (c, tier, admin) => !!(c.tiers[tier].sale || (admin && tier !== 'weekly'));
// on sale for this viewer: the tier's own switch, or the admin portal's tier test (Admin > Game Pass) while sovTiers is off
const tierOpen = (c, tier, preview) => !!(c.tiers[tier].sale || (preview && tier !== 'weekly'));
const PACKAGE_USD = [5, 10, 20, 50, 100, 250, 500]; // copy only: the package that covers a price
const packageFor = usd => PACKAGE_USD.find(x => x >= usd) || usd;
// GET /api/my/gamepass. opts.admin = the ADMIN_EMAIL account (sees every tier while sovTiers is off).
// GET /api/my/gamepass: exactly what a member sees, for EVERY account, the admin's included (2026-10-25, Marty: no admin-only
// tier UI on the member card). opts.preview = the admin portal's tier test (GET /api/admin/gamepass/preview): every tier, each
// one open to the admin's own account while sovTiers is off.
function view(email, now, opts) {
const e = String(email || '').toLowerCase(); const c = cfg(); const t = now || Date.now(); const f = flag(e, t); const p = rec(e); const w = waitingOrder(e, 'weekly');
const admin = !!(opts && opts.admin); const T = tiersOf(p);
const admin = !!(opts && opts.preview); const T = tiersOf(p);
const caps = capsFor(e, t);
// the tier rows this member sees: weekly always; a higher tier while on sale, to the admin, or to a current holder (holders
// the tier rows this member sees: weekly always; a higher tier while on sale, in the admin preview, or to a current holder (holders
// keep their pass when a sale is switched off, they just cannot buy more)
const passRows = TIERS.filter(k => k === 'weekly' || c.tiers[k].sale || admin || T[k] > t).map(k => {
const tc = c.tiers[k]; return { tier: k, name: TIER_NAMES[k], perks: TIER_DEF[k].perks, price: tc.price, usd: tc.price / 100, days: tc.days, package: packageFor(tc.price / 100),
active: T[k] > t, until: T[k] > t ? T[k] : null, waiting: !!waitingOrder(e, k), open: k === 'weekly' ? c.enabled : tierOpen(c, k, admin) };
active: T[k] > t, until: T[k] > t ? T[k] : null, waiting: !!waitingOrder(e, k), sale: !!tc.sale, open: k === 'weekly' ? c.enabled : tierOpen(c, k, admin) };
});
const tiered = passRows.some(r => r.tier !== 'weekly');
return { enabled: c.enabled, active: f.active, until: f.until, tier: f.tier, price: c.price, days: c.days, usd: c.price / 100,
@@ -199,7 +206,8 @@ function view(email, now, opts) {
show: c.enabled || tiered, passes: passRows, tierPreview: tiered && admin && !c.tierSales };
}
// POST /api/my/gamepass/buy { tier }. tier missing = weekly (exactly the pass as it was before tiers). opts.admin = the ADMIN_EMAIL account.
// POST /api/my/gamepass/buy { tier }. tier missing = weekly (exactly the pass as it was before tiers). opts.preview = the admin
// portal's tier test (POST /api/admin/gamepass/test-buy, the admin's own account only): a tier that is not on sale still opens an order.
// A pass is ALWAYS paid by a fresh package purchase (2026-10-22, Marty: the pass rides the package rail so sponsors get paid). This never
// spends credits: it opens (or reuses) a waiting order for that tier and sends the member to buy a package of at least the tier price.
// The order is fulfilled by onEvent() below; the member keeps every credit of that package for ads.
@@ -209,7 +217,7 @@ function buy(email, now, tier, opts) {
if (!tierOk(tier)) return { error: 'There is no such pass.' };
const tc = c.tiers[tier]; const name = TIER_NAMES[tier];
if (tier === 'weekly') { if (!c.enabled) return { error: 'The Game Pass is not open yet.' }; }
else if (!tierOpen(c, tier, !!(opts && opts.admin))) return { error: 'The ' + name + ' pass is not open yet.' };
else if (!tierOpen(c, tier, !!(opts && opts.preview))) return { error: 'The ' + name + ' pass is not open yet.' };
let w = waitingOrder(e, tier); const reused = !!w;
if (!w) { const k = 'gp-' + t.toString(36) + '-' + Math.random().toString(36).slice(2, 8); orders.set(k, { status: 'waiting', email: e, ts: t, tier }); w = Object.assign({ order: k }, orders.get(k)); }
const pkg = packageFor(tc.price / 100);
@@ -491,5 +499,5 @@ function prune(now) {
return n;
}
module.exports = { init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, flag, view, buy, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey,
module.exports = { init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, flag, view, buy, cancelOrder, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey,
_ledger: () => L };
+14 -2
View File
@@ -61,6 +61,14 @@
.kv-row .k{font-family:var(--mono);font-size:12.5px;overflow-wrap:anywhere}
.kv-row input[type=checkbox]{width:auto;justify-self:start}
@media(max-width:700px){.kv-row{grid-template-columns:1fr}}
.gpt-note{margin:0 0 10px;padding:8px 12px;border-radius:8px;background:#fde68a;color:#7c2d12;font-size:13px}
.gpt-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px}
.gpt-tier{border:1px dashed var(--line-strong);border-radius:12px;padding:12px 14px;display:flex;flex-direction:column;gap:4px}
.gpt-tier.on{border-style:solid;border-color:var(--gold,#e2b04a);box-shadow:0 0 0 1px var(--gold,#e2b04a) inset}
.gpt-tier h4{margin:0;font-size:16px;display:flex;gap:6px;align-items:center;flex-wrap:wrap}
.gpt-tier .gpt-price{margin:0;font-size:18px;font-weight:700}
.gpt-tier ul{margin:4px 0;padding-left:18px;font-size:13px}
.gpt-tier .gpt-acts{display:flex;gap:6px;flex-wrap:wrap;margin-top:auto;padding-top:6px}
</style>
</head>
<body class="bo-body">
@@ -564,6 +572,10 @@
<div class="card-head"><h3>By pass tier</h3><span class="sub" id="gpTiersSub"></span></div>
<div id="gpTiers" class="small">…</div>
</div>
<div class="card" id="gpTestCard">
<div class="card-head"><h3>Tier test and preview</h3><span class="sub" id="gpTestSub">admin only · your own account</span></div>
<div id="gpTest" class="small">…</div>
</div>
<div class="card">
<div class="card-head"><h3>Pass sales</h3><span class="sub" id="gpSalesSub"></span></div>
<div id="gpSales" class="small">…</div>
@@ -572,7 +584,7 @@
<div class="card-head"><h3>Comp a pass</h3><span class="sub">support: one pass period, recorded as no sale</span></div>
<p style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin:0"><input id="gpCompEmail" placeholder="member email" style="max-width:260px"><select id="gpCompTier"><option value="weekly">Game Pass (weekly)</option><option value="explorer">Explorer (monthly)</option><option value="champion">Champion (monthly)</option><option value="sovereign">Sovereign (monthly)</option><option value="legend">Legend (yearly)</option></select><input id="gpCompWhy" placeholder="why" style="max-width:220px"><button class="btn small" id="gpComp" type="button">Give one pass period</button><button class="btn small sec" id="gpRevoke" type="button">End this tier now (refund)</button></p>
</div>
<p class="small muted">Every pass is paid by a new package purchase of at least its price (since 2026-10-22; credits never buy a pass). The *PriceCredits settings are the pass price in cents. Settings live in Settings &rsaquo; Site settings: gamePassEnabled (1/0), gamePassPriceCredits, gamePassDays, capFreeDaily, capFreeTotal, capPassDaily, capPassTotal, capsStartDate (Central YYYY-MM-DD; empty = caps recorded, not enforced), passTournamentPct, telegramGamesTopicId. Tiers above weekly: sovTiers (1/0, the sale switch for all of them; off = only the admin account sees them), gamePassExplorerEnabled / gamePassChampionEnabled / gamePassSovereignEnabled / gamePassLegendEnabled (0 stops one tier), gamePassExplorerPriceCredits (1999), gamePassChampionPriceCredits (3999), gamePassSovereignPriceCredits (9999), gamePassLegendPriceCredits (24999), gamePassExplorerDays / gamePassChampionDays / gamePassSovereignDays (30), gamePassLegendDays (365), passTournamentTierSales (1 = their sales feed the tournament pool; default 0). Prize POL is paid by the games from their faucets (GET /api/partner/tournament/pending), not from here.</p>
<p class="small muted">Every pass is paid by a new package purchase of at least its price (since 2026-10-22; credits never buy a pass). The *PriceCredits settings are the pass price in cents. Settings live in Settings &rsaquo; Site settings: gamePassEnabled (1/0), gamePassPriceCredits, gamePassDays, capFreeDaily, capFreeTotal, capPassDaily, capPassTotal, capsStartDate (Central YYYY-MM-DD; empty = caps recorded, not enforced), passTournamentPct, telegramGamesTopicId. Tiers above weekly: sovTiers (1/0, the sale switch for all of them; off = members never see them and the admin tests them in Tier test and preview above, never on the member card), gamePassExplorerEnabled / gamePassChampionEnabled / gamePassSovereignEnabled / gamePassLegendEnabled (0 stops one tier), gamePassExplorerPriceCredits (1999), gamePassChampionPriceCredits (3999), gamePassSovereignPriceCredits (9999), gamePassLegendPriceCredits (24999), gamePassExplorerDays / gamePassChampionDays / gamePassSovereignDays (30), gamePassLegendDays (365), passTournamentTierSales (1 = their sales feed the tournament pool; default 0). Prize POL is paid by the games from their faucets (GET /api/partner/tournament/pending), not from here.</p>
</div>
<div class="pane" id="pane-settings" hidden>
@@ -629,6 +641,6 @@
<script src="/assets/common.js?v=20261023ov"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/admin-kb.js?v=20261020kb"></script>
<script src="/assets/admin.js?v=20261023ov"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script><script src="/assets/admin-kits.js?v=20261024kit"></script>
<script src="/assets/admin.js?v=20261025gp"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script><script src="/assets/admin-kits.js?v=20261024kit"></script>
</body>
</html>
+48
View File
@@ -1225,6 +1225,7 @@
$('gpSales').innerHTML = !SL.length ? '<p class="muted">No pass sold yet.</p>' : '<table class="adm-table"><tr><th>When</th><th>Member</th><th>Pass</th><th>Paid by</th><th class="num">Pass</th><th class="num">Package</th><th>Package tx</th></tr>'
+ SL.map(x => '<tr><td style="white-space:nowrap">' + when(x.ts) + '</td><td>' + esc(x.email) + '</td><td>' + esc(x.name || x.tier) + '</td><td>' + esc(x.label) + (x.credits ? ' · ' + x.credits + ' cr' : '') + '</td><td class="num">' + usd(x.usd) + '</td><td class="num">' + (x.packageUsd ? usd(x.packageUsd) : '') + '</td><td>' + txLink(x.tx) + '</td></tr>').join('')
+ '</table>';
await loadGpTest();
$('gpTourSub').textContent = (T.lastRun ? 'last settled ' + when(T.lastRun) : 'never run') + ' · next Monday 9 AM Central (' + when(T.next) + ') · ' + (T.pending || 0) + ' prize' + (T.pending === 1 ? '' : 's') + ' unpaid';
const L = T.last;
$('gpTour').innerHTML = !L ? '<p class="muted">No week settled yet. The job runs hourly and settles the closed week once Monday 9 AM Central has passed; ' + S.pct + '% of that week\u2019s pass sales becomes the POL prize pool (50 / 30 / 20).</p>'
@@ -1232,6 +1233,53 @@
+ (L.winners && L.winners.length ? '<table class="adm-table">' + L.winners.map(w => '<tr><td>#' + w.place + ' ' + esc(w.username ? '@' + w.username : w.email) + '</td><td>' + w.score + ' plays</td><td class="num">' + pol(w.pol) + ' POL</td><td>' + esc(w.status) + (w.tx ? ' · ' + esc(String(w.tx).slice(0, 12)) : '') + '</td></tr>').join('') + '</table>' : '<p class="muted">No pass holder reported any plays that week.</p>')
+ ((T.history || []).length > 1 ? '<p class="muted" style="margin:8px 0 0">Earlier: ' + T.history.slice(1).map(h => esc(h.label) + ' (' + (h.sales || 0) + ' sold, ' + pol(h.poolPol) + ' POL)').join(' · ') + '</p>' : '');
}
// Tier test and preview (2026-10-25, Marty): the member Games card shows the admin exactly what a member sees, so every tier test lives
// here. Every action touches ONLY the signed-in admin's own account; a test buy opens the same waiting order a member gets (a fresh
// package on /my fulfils it, sponsors paid as usual), a test comp starts the tier at once with no sale recorded.
async function loadGpTest() {
const box = $('gpTest'); if (!box) return;
let g; try { g = await api('/api/admin/gamepass/preview'); } catch (e) { box.innerHTML = '<p class="muted">' + esc(e.message) + '</p>'; return; }
const ct = ms => new Date(Number(ms)).toLocaleDateString('en-US', { timeZone: 'America/Chicago', weekday: 'short', month: 'short', day: 'numeric' }) + ' (Central)';
const len = d => d >= 365 && d % 365 === 0 ? (d === 365 ? '1 year' : (d / 365) + ' years') : d + ' days';
const rows = g.passes || [];
$('gpTestSub').textContent = 'TEST / PREVIEW · admin only · acts on your own account: ' + g.email;
const card = r => {
const sale = r.tier === 'weekly' ? !!g.enabled : !!r.sale;
const st = r.active ? '<b>Your account: active until ' + esc(ct(r.until)) + '</b>' : r.waiting ? '<b>Your account: test order waiting for a $' + r.package + ' package</b>' : 'Your account: not active';
const acts = (r.waiting ? '<a class="btn small" href="/my?from=gamepass#buy" target="_blank" rel="noopener">Buy the $' + r.package + ' package on /my</a><button class="btn small sec" type="button" data-gpt-cancel="' + esc(r.tier) + '">Cancel test order</button>'
: '<button class="btn small" type="button" data-gpt-buy="' + esc(r.tier) + '">Test buy (real order, $' + r.package + ' package)</button>')
+ '<button class="btn small sec" type="button" data-gpt-comp="' + esc(r.tier) + '">Give my account ' + esc(r.name) + ' now (test)</button>'
+ (r.active ? '<button class="btn small sec" type="button" data-gpt-end="' + esc(r.tier) + '">End my ' + esc(r.name) + ' now</button>' : '');
return '<div class="gpt-tier' + (r.active ? ' on' : '') + '"><h4>' + esc(r.name) + ' <span class="chip flat">' + (sale ? 'on sale: members see it' : 'hidden from members') + '</span></h4>'
+ '<p class="gpt-price">$' + r.usd + ' <span class="small muted">for ' + len(r.days) + '</span></p>'
+ '<ul>' + (r.perks || []).map(x => '<li>' + esc(x) + '</li>').join('') + '</ul>'
+ '<p class="small" style="margin:4px 0">' + st + '</p><div class="gpt-acts">' + acts + '</div></div>';
};
box.innerHTML = '<p class="gpt-note"><b>Test / preview, admin only.</b> ' + (g.tierPreview ? 'The passes above the weekly Game Pass are hidden from members until sovTiers is switched on in Settings (it stays off until the paid tiers launch). ' : '')
+ 'These are the tier cards as members will see them. Every button here acts on your own account (' + esc(g.email) + ') and nobody else’s. The member Games card on /my shows you exactly what a member sees: while you hold a test tier it shows that tier the way it would for any member who holds one.</p>'
+ '<div class="gpt-grid">' + rows.map(card).join('') + '</div>'
+ '<p class="muted" style="margin:10px 0 0"><b>Test buy</b> opens the same waiting order a member gets: a fresh package of at least the price, bought on /my by one of your positions, starts it (sponsors paid as usual). Cancel a test order you will not pay, or a later real package of that size fulfils it. <b>Give my account</b> starts one pass period at once, recorded as comped (no sale); <b>End</b> stops it. '
+ 'To test it in game, open <b>Shards of Valor &gt; Passes</b> (key P) after signing in to the game again from /my Games: the game reads your highest tier from InstantAdPay at sign-in.</p>';
const tierName = k => (rows.find(r => r.tier === k) || {}).name || k;
box.querySelectorAll('[data-gpt-buy]').forEach(b => b.addEventListener('click', busy(b, async () => {
const k = b.dataset.gptBuy; const r = rows.find(x => x.tier === k);
if (!(await IAP.confirmBox('Open a TEST order for ' + tierName(k) + ' on your own account (' + g.email + ')? It starts when a fresh $' + r.package + ' or bigger package from one of your positions settles on chain. Members still cannot see or buy this tier.', { title: 'Test buy: ' + tierName(k), ok: 'Open the test order', cancel: 'Not now' }))) return;
const x = await api('/api/admin/gamepass/test-buy', { tier: k }); IAP.status('Test order for ' + tierName(k) + ' is waiting for a $' + x.package + ' package on ' + x.email + '.', 'ok'); await loadGpTest();
})));
box.querySelectorAll('[data-gpt-cancel]').forEach(b => b.addEventListener('click', busy(b, async () => {
const k = b.dataset.gptCancel; await api('/api/admin/gamepass/test-cancel', { tier: k }); IAP.status('Test order for ' + tierName(k) + ' cancelled.', 'ok'); await loadGpTest();
})));
box.querySelectorAll('[data-gpt-comp]').forEach(b => b.addEventListener('click', busy(b, async () => {
const k = b.dataset.gptComp;
if (!(await IAP.confirmBox('Give your own account (' + g.email + ') one ' + tierName(k) + ' period now, for testing? It is recorded as comped (no sale) and shows in the game the next time you sign in to it.', { title: 'Test ' + tierName(k), ok: 'Give it to me', cancel: 'Not now' }))) return;
const x = await api('/api/admin/gamepass/test-comp', { tier: k }); IAP.status(tierName(k) + ' on your account until ' + when(x.until) + ' (test).', 'ok'); await loadGamePass();
})));
box.querySelectorAll('[data-gpt-end]').forEach(b => b.addEventListener('click', busy(b, async () => {
const k = b.dataset.gptEnd;
if (!(await IAP.confirmBox('End ' + tierName(k) + ' on your own account now?', { title: 'End test tier', ok: 'End it now', cancel: 'Keep it' }))) return;
await api('/api/admin/gamepass/revoke', { email: g.email, tier: k, why: 'admin tier test' }); IAP.status(tierName(k) + ' on your account ended.', 'ok'); await loadGamePass();
})));
}
$('gpTourRun').addEventListener('click', busy($('gpTourRun'), async () => { const r = await api('/api/admin/gamepass/tournament/run', {}); IAP.status('Settled ' + r.label + ': ' + (r.winners || []).length + ' winner(s), pool ' + Number(r.poolPol || 0).toFixed(2) + ' POL.', 'ok'); await loadGamePass(); }));
$('gpComp').addEventListener('click', busy($('gpComp'), async () => { const r = await api('/api/admin/gamepass/comp', { email: $('gpCompEmail').value, why: $('gpCompWhy').value, tier: $('gpCompTier').value }); IAP.status((r.tier || 'weekly') + ' pass on ' + r.email + ' until ' + when(r.until) + '.', 'ok'); $('gpCompEmail').value = ''; await loadGamePass(); }));
$('gpRevoke').addEventListener('click', busy($('gpRevoke'), async () => {
+1 -2
View File
@@ -1907,7 +1907,6 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
};
card.hidden = false; card.classList.toggle('gp-hl', !!highlight);
card.innerHTML = '<div class="card-head"><h3>\u{1F39F}️ Game Passes</h3><span class="sub">weekly, monthly or yearly · every game</span></div>'
+ (gp.tierPreview ? '<p class="small" style="margin:0 0 8px;padding:6px 10px;border-radius:8px;background:#fde68a;color:#7c2d12"><b>Admin preview.</b> The passes above the weekly Game Pass are hidden from members until sovTiers is switched on in Settings.</p>' : '')
+ '<p style="margin:0 0 8px">' + state + '</p>'
+ '<p>Free play pays real POL every day, and the main story of Shards of Valor is free for everyone. Every pass gives the same higher POL caps in every game. Each higher pass includes everything below it and adds more of Shards of Valor: weapons, gear, bonus islands, heroes and a higher level cap. <b>Paid passes add heroes, islands, a higher level cap and new looks.</b> Pass gear is never better than gear players can earn, and passes never pay more POL.</p>'
+ '<div class="gp-tiers">' + rows.map(box).join('') + '</div>'
@@ -1956,7 +1955,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
if ((gp.passes || []).some(r => r.tier !== 'weekly')) return renderPassTiers(card, gp, highlight);
// Five Dollar Friday + the pass (Marty 2026-10-23): the package that starts the pass also gets the Friday bonus, so say so on Fridays
let fdf = ''; try { const f = await (await fetch('/api/friday')).json(); if (f && f.on && f.live) { const base = gp.price || 500, got = Math.round(base * (1 + (Number(f.pct) || 20) / 100));
fdf = '<p style="margin:0 0 10px;padding:8px 10px;border-radius:8px;background:rgba(226,176,74,.12);border:1px solid rgba(226,176,74,.35)">\u{1F383} <b>It\u2019s Five Dollar Friday.</b> The $' + (gp.usd || 5) + ' package that starts your pass gets +' + (Number(f.pct) || 20) + '% too, so you get the ' + (gp.days || 7) + '-day pass <b>and keep ' + got.toLocaleString() + ' ad credits</b>. Tap Get the Pass first, then buy the package.</p>'; } } catch (e) {} // a tier above weekly on sale (or admin preview, or a holder)
fdf = '<p style="margin:0 0 10px;padding:8px 10px;border-radius:8px;background:rgba(226,176,74,.12);border:1px solid rgba(226,176,74,.35)">\u{1F383} <b>It\u2019s Five Dollar Friday.</b> The $' + (gp.usd || 5) + ' package that starts your pass gets +' + (Number(f.pct) || 20) + '% too, so you get the ' + (gp.days || 7) + '-day pass <b>and keep ' + got.toLocaleString() + ' ad credits</b>. Tap Get the Pass first, then buy the package.</p>'; } } catch (e) {} // the tier boxes above show only when a tier above weekly is on sale or the member holds one (never an admin-only view: tier tests live in Admin > Game Pass)
const caps = gp.caps || {}; const price = gp.price || 500;
const state = gp.active ? '<span class="badge" style="background:var(--gold,#e2b04a);color:#111">Pass active \u00b7 until ' + esc(gpDate(gp.until)) + '</span>'
: gp.waiting ? '<span class="badge amber">Waiting for a $' + (gp.usd || 5) + ' package</span>' : '<span class="badge">Not active</span>';
+1 -1
View File
@@ -1223,7 +1223,7 @@
<script src="/assets/wallet.js?v=20260911a"></script>
<script src="/assets/promo.js?v=20261016p"></script>
<script src="/assets/support.js?v=20261016a"></script>
<script src="/assets/my.js?v=20261024ct"></script>
<script src="/assets/my.js?v=20261025gp"></script>
<script src="/assets/fuel.js?v=20261024rg"></script>
<script src="/assets/engine-room.js?v=20261024rg"></script>
<script src="/assets/chat.js?v=20261016n"></script>
+55 -26
View File
@@ -10,6 +10,9 @@
// fresh package purchase (faked locally with /api/dev/gamepass-purchase), and the card sends the member to Buy credits.
// 2026-10-22: + Sovereign / Legend: members refused while sovTiers is off, the admin preview lists all five, the admin buys Sovereign
// (real charge), a Legend waiting order is settled by a $250 package (a year), the token / partner player carry tier legend + tiers.
// 2026-10-25 (Marty): no admin-only tier UI on the member card. The ADMIN_EMAIL account gets the member view on /my (weekly only,
// hidden-tier buys refused there too); every tier test runs from Admin > Game Pass > Tier test and preview (/api/admin/gamepass/preview,
// test-buy, test-cancel, test-comp), always on the admin's own account. A holder of a tier sees it on the card like any member.
import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
@@ -91,32 +94,58 @@ try {
const txt = await page.textContent('#gpCard'); ok(!/Explorer|Champion|Sovereign|Legend/.test(txt) && errs.length === 0, 'member page: the weekly card as before, no Explorer/Champion/Sovereign/Legend text, no page errors', errs.join(' | '));
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '1-member-weekly-only.png') }); await ctx.close(); }
// 2. the admin: preview of all three, buys Explorer in the browser with the seeded purchased credits (the real charge)
// 2. the admin account on /my gets the MEMBER view (2026-10-25): weekly only, no preview note, hidden tiers refused on the member route
g = (await api('/api/my/gamepass', null, hA)).j;
ok(g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && g.passes.map(x => x.price).join() === '500,1999,3999,9999,24999', 'admin, sovTiers off: preview with all five tiers, 500 / 1999 / 3999 / 9999 / 24999', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open])));
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my?from=shardsofvalor#passes');
await page.waitForSelector('#gpCard [data-gp-tier="explorer"]', { timeout: 15000 }); await sleep(600); await hide(page);
ok(g.passes && g.passes.length === 1 && g.passes[0].tier === 'weekly' && !g.tierPreview, 'admin on /my, sovTiers off: the member view, weekly only, no preview', JSON.stringify((g.passes || []).map(x => x.tier)));
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
ok(r.status === 400 && r.j.error === 'The Explorer pass is not open yet.', 'admin on the member route: Explorer refused like any member (tests moved to Admin > Game Pass)', JSON.stringify(r.j));
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my#passes'); await page.waitForSelector('#gpCard:not([hidden]) #gpBuy', { timeout: 15000 }); await sleep(600); await hide(page);
const txt = await page.textContent('#gpCard');
ok(/never make you stronger than players who earn their gear/.test(txt) && /main story of Shards of Valor is free/.test(txt) && /Admin preview/.test(txt) && !/\u2014/.test(txt), 'tier card copy: never stronger, main story free, admin preview note, no em dashes', '');
ok(/#games/.test(page.url()), 'the Shards of Valor link (#passes) lands on the pass card, not the Buy pane', page.url());
ok(/Sovereign/.test(txt) && /Necromancer/.test(txt) && /Legend/.test(txt) && /\$249\.99/.test(txt) && /for 1 year/.test(txt) && /Archer/.test(txt) && /Druid/.test(txt) && /level cap 30/.test(txt) && /\$19\.99/.test(txt), 'admin preview card lists Sovereign and Legend ($249.99 for 1 year) with what each includes', '');
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-preview-all-tiers.png') });
await page.click('#gpCard [data-gp-tier="explorer"]'); await page.waitForSelector('#dlgOk', { timeout: 5000 });
await page.screenshot({ path: path.join(SHOTS, '3-admin-confirm-explorer.png') });
ok(!/Explorer|Champion|Sovereign|Legend|Admin preview/.test(txt) && errs.length === 0, 'admin /my Games card: the weekly card a member sees, no tier boxes, no admin preview note', errs.join(' | '));
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-member-card-weekly-only.png') }); await ctx.close(); }
// the admin portal preview: all five tiers with what each includes, every one open to the admin's own account
g = (await api('/api/admin/gamepass/preview', null, adminH)).j;
ok(g.test === true && g.email === ADMIN_EMAIL && g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && g.passes.map(x => x.price).join() === '500,1999,3999,9999,24999' && g.passes.every(x => x.open) && g.passes.filter(x => x.tier !== 'weekly').every(x => x.sale === false), 'GET /api/admin/gamepass/preview: all five tiers (500 / 1999 / 3999 / 9999 / 24999), open to the admin, none on sale', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open, x.sale])));
ok((await api('/api/admin/gamepass/preview', null, hM)).status === 401 && (await api('/api/admin/gamepass/test-buy', { data: { tier: 'explorer' } }, hM)).status === 401, 'tier test endpoints refuse a member session (401)', '');
// test cancel + test comp + end, on the admin's own account
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'champion' } }, adminH);
ok(r.status === 200 && r.j.needPay && r.j.tier === 'champion' && r.j.email === ADMIN_EMAIL && r.j.package === 50, 'test-buy Champion: a waiting order for a $50 package on the admin account', JSON.stringify(r.j));
r = await api('/api/admin/gamepass/test-cancel', { data: { tier: 'champion' } }, adminH);
g = (await api('/api/admin/gamepass/preview', null, adminH)).j;
ok(r.j.ok && r.j.order && !g.passes.find(x => x.tier === 'champion').waiting, 'test-cancel drops the Champion test order', JSON.stringify(r.j));
r = await api('/api/admin/gamepass/test-comp', { data: { tier: 'champion' } }, adminH);
ok(r.j.ok && r.j.tier === 'champion' && r.j.email === ADMIN_EMAIL && r.j.until > Date.now(), 'test-comp Champion starts one period on the admin account at once', JSON.stringify(r.j));
r = await api('/api/admin/gamepass/revoke', { data: { email: ADMIN_EMAIL, tier: 'champion', why: 'admin tier test' } }, adminH);
g = (await api('/api/my/gamepass', null, hA)).j;
ok(r.j.ok && !g.active && g.passes.length === 1, 'ending the test Champion puts the admin card back to the weekly member view', JSON.stringify({ a: g.active, rows: g.passes.map(x => x.tier) }));
{ const ctx = await browser.newContext({ viewport: { width: 1280, height: 1000 } }); const page = await ctx.newPage(); const errs = []; page.on('pageerror', e => errs.push(String(e)));
await page.goto(B + '/admin', { waitUntil: 'networkidle' });
await page.fill('#adEmail', ADMIN_EMAIL); await page.click('#adSend'); await page.waitForSelector('#adVerify:not([hidden])'); await page.click('#adVerify'); await sleep(1200);
const nav = await page.$('.bo-menu [data-pane="gamepass"]'); if (nav) { await nav.click(); await page.waitForSelector('#gpTest [data-gpt-buy="explorer"]', { timeout: 10000 }).catch(() => {}); }
let txt = await page.textContent('#gpTest').catch(() => '');
ok(/Test \/ preview, admin only/.test(txt) && /hidden from members/.test(txt) && /Sovereign/.test(txt) && /Necromancer/.test(txt) && /Legend/.test(txt) && /\$249\.99/.test(txt) && /for 1 year/.test(txt) && /Archer/.test(txt) && /Druid/.test(txt) && /level cap 30/.test(txt) && /\$19\.99/.test(txt) && /Shards of Valor > Passes/.test(txt) && !/\u2014/.test(txt) && errs.length === 0, 'Admin > Game Pass > Tier test and preview: labelled test/preview, all five tiers with what each includes, no em dashes', errs.join(' | ') || (nav ? '' : 'admin nav not found'));
await page.locator('#gpTestCard').scrollIntoViewIfNeeded(); await sleep(300);
await page.locator('#gpTestCard').screenshot({ path: path.join(SHOTS, '3-admin-tier-test-panel.png') });
await page.click('#gpTest [data-gpt-buy="explorer"]'); await page.waitForSelector('#dlgOk', { timeout: 5000 });
await page.screenshot({ path: path.join(SHOTS, '3b-admin-confirm-test-explorer.png') });
await page.click('#dlgOk');
await page.waitForFunction(() => /#buy/.test(location.hash) || !!document.querySelector('.pane.on#pane-buy, [data-pane="buy"].on'), null, { timeout: 10000 }).catch(() => {});
await sleep(800);
ok(errs.length === 0, 'Get Explorer: no page errors, the member is sent to buy a package', page.url() + ' ' + errs.join(' | '));
await page.screenshot({ path: path.join(SHOTS, '4-admin-sent-to-buy.png') });
let g1 = (await api('/api/my/gamepass', null, hA)).j; const ex1 = g1.passes.find(x => x.tier === 'explorer');
ok(!g1.active && ex1 && ex1.waiting === true && !ex1.active, 'the click opened a waiting Explorer order; nothing active yet', JSON.stringify(ex1));
ok(!/gamepass bought with credits/.test(srvLog), 'no credit charge: the seeded purchased credits were not spent on the pass', '');
const dv0 = (await api('/api/dev/gamepass-purchase', { data: { cents: 2000, email: ADMIN_EMAIL } })).j;
ok(dv0 && dv0.order && dv0.order.tier === 'explorer', 'a fresh $20 package fulfils the Explorer order', JSON.stringify(dv0));
await page.goto(B + '/my#passes'); await page.waitForFunction(() => /Explorer active/.test((document.getElementById('gpCard') || {}).textContent || ''), null, { timeout: 15000 }).catch(() => {});
await page.waitForFunction(() => /test order waiting for a \$20 package/.test((document.getElementById('gpTest') || {}).textContent || ''), null, { timeout: 10000 }).catch(() => {});
txt = await page.textContent('#gpTest').catch(() => '');
ok(/test order waiting for a \$20 package/.test(txt) && errs.length === 0, 'Test buy Explorer from the admin panel: the card shows the waiting test order', errs.join(' | '));
await page.locator('#gpTestCard').screenshot({ path: path.join(SHOTS, '4-admin-test-order-waiting.png') }); await ctx.close(); }
let g1 = (await api('/api/admin/gamepass/preview', null, adminH)).j; const ex1 = g1.passes.find(x => x.tier === 'explorer');
ok(!g1.active && ex1 && ex1.waiting === true && !ex1.active, 'the click opened a waiting Explorer order; nothing active yet', JSON.stringify(ex1));
ok(!/gamepass bought with credits/.test(srvLog), 'no credit charge: the seeded purchased credits were not spent on the pass', '');
const dv0 = (await api('/api/dev/gamepass-purchase', { data: { cents: 2000, email: ADMIN_EMAIL } })).j;
ok(dv0 && dv0.order && dv0.order.tier === 'explorer', 'a fresh $20 package fulfils the Explorer test order', JSON.stringify(dv0));
// a HOLDER sees the tier on the member card the way any member holding it would (no preview note, nothing they cannot buy listed)
{ const { page, errs, ctx } = await pageFor(hA); await page.goto(B + '/my?from=shardsofvalor#passes');
await page.waitForFunction(() => /Explorer active/.test((document.getElementById('gpCard') || {}).textContent || ''), null, { timeout: 15000 }).catch(() => {});
await sleep(600); await hide(page);
const after = await page.textContent('#gpCard');
ok(/Explorer active/.test(after) && errs.length === 0, 'after the package the card shows Explorer active (Central date)', errs.join(' | '));
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '5-admin-explorer-active.png') }); await ctx.close(); }
ok(/#games/.test(page.url()), 'the Shards of Valor link (#passes) lands on the pass card, not the Buy pane', page.url());
ok(/Explorer active/.test(after) && /never better than gear players can earn/.test(after) && /main story of Shards of Valor is free/.test(after) && !/Admin preview|Champion|Sovereign|Legend/.test(after) && !/\u2014/.test(after) && errs.length === 0, 'holder card: Explorer active, weekly + Explorer only, no admin preview, no em dashes', errs.join(' | '));
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '5-admin-explorer-active-holder-card.png') }); await ctx.close(); }
g = (await api('/api/my/gamepass', null, hA)).j;
const ex = g.passes.find(x => x.tier === 'explorer');
ok(g.active && g.tier === 'explorer' && ex.active && Math.abs(ex.until - (Date.now() + 30 * 86400000)) < 120000, 'GET /api/my/gamepass: tier explorer, 30 days', JSON.stringify({ tier: g.tier, until: ex && new Date(ex.until).toISOString() }));
@@ -137,18 +166,18 @@ try {
// 3b. Sovereign (9999 credits, 30 days) and the yearly Legend (24999, 365 days), 2026-10-22: the admin buys Sovereign through the
// real charge, then is short for Legend (waiting order, $250 package) and for a second Explorer; a $250 package settles Legend.
r = await api('/api/my/gamepass/buy', { data: { tier: 'sovereign' } }, hA);
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'sovereign' } }, adminH);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'sovereign' && r.j.package === 100, 'admin Sovereign (sovTiers off, testing): a waiting order for a $100 package, credits untouched', JSON.stringify(r.j));
let dvS = (await api('/api/dev/gamepass-purchase', { data: { cents: 10000, email: ADMIN_EMAIL } })).j;
ok(dvS && dvS.order && dvS.order.tier === 'sovereign' && Math.abs(dvS.order.until - (Date.now() + 30 * 86400000)) < 120000, 'a fresh $100 package fulfils Sovereign: 30 days', JSON.stringify(dvS));
ok(!/gamepass bought with credits/.test(srvLog), 'still no credit charge anywhere', '');
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'explorer' } }, adminH);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && /package of \$20 or more/.test(r.j.message), 'a second Explorer -> waiting order, "package of $20 or more"', JSON.stringify({ needPay: r.j.needPay, payUrl: r.j.payUrl, msg: r.j.message }));
r = await api('/api/my/gamepass/buy', { data: { tier: 'legend' } }, hA);
r = await api('/api/admin/gamepass/test-buy', { data: { tier: 'legend' } }, adminH);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'legend' && r.j.price === 24999 && r.j.payUrl === '/my?from=gamepass&tier=legend#buy' && /package of \$250 or more/.test(r.j.message), 'Legend: waiting order, "package of $250 or more", payUrl with tier', JSON.stringify({ needPay: r.j.needPay, payUrl: r.j.payUrl, msg: r.j.message }));
let dv = (await api('/api/dev/gamepass-purchase', { data: { cents: 10000, email: ADMIN_EMAIL } })).j;
ok(dv && dv.order && dv.order.tier === 'explorer' && dv.order.until === ex.until + 30 * 86400000, 'a $100 package fulfils the waiting Explorer (extends it from its end), never Legend', JSON.stringify(dv));
g = (await api('/api/my/gamepass', null, hA)).j;
g = (await api('/api/admin/gamepass/preview', null, adminH)).j;
ok(!g.passes.find(x => x.tier === 'legend').active && g.passes.find(x => x.tier === 'legend').waiting, 'Legend still waiting after a $100 package', JSON.stringify(g.passes.find(x => x.tier === 'legend')));
dv = (await api('/api/dev/gamepass-purchase', { data: { cents: 25000, email: ADMIN_EMAIL } })).j;
ok(dv && dv.order && dv.order.tier === 'legend' && Math.abs(dv.order.until - (Date.now() + 365 * 86400000)) < 120000, 'a $250 package fulfils the Legend order: a year', JSON.stringify(dv));
+4 -3
View File
@@ -53,9 +53,10 @@ async function buyX(email, payer, now, tier, opts) {
ok(!passes.get('a@x.com'), 'a refused buy writes nothing', '');
let v = gp.view('a@x.com', T0);
ok(v.passes.length === 1 && v.passes[0].tier === 'weekly' && v.show === true && v.tierPreview === false, 'sovTiers off: a member sees only the weekly pass', JSON.stringify(v.passes.map(x => x.tier)));
v = gp.view('admin@x.com', T0, { admin: true });
v = gp.view('admin@x.com', T0); ok(v.passes.length === 1 && !v.tierPreview, 'the member view (GET /api/my/gamepass) is the same for the admin account: weekly only (2026-10-25)', JSON.stringify(v.passes.map(x => x.tier)));
v = gp.view('admin@x.com', T0, { preview: true }); // Admin > Game Pass > Tier test and preview
ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign,legend' && v.tierPreview === true && v.passes.slice(1).every(x => x.open === true) && v.passes.map(x => x.price).join() === '500,1999,3999,9999,24999' && v.passes.map(x => x.days).join() === '7,30,30,30,365' && v.passes.map(x => x.package).join() === '5,20,50,100,250', 'sovTiers off: the admin sees all five (preview), prices 500 / 1999 / 3999 / 9999 / 24999, days 7 / 30 / 30 / 30 / 365, packages $5 / $20 / $50 / $100 / $250', JSON.stringify(v.passes));
r = await buyX('admin@x.com', paid, T0, 'explorer', { admin: true });
r = await buyX('admin@x.com', paid, T0, 'explorer', { preview: true });
ok(r.ok && r.tier === 'explorer' && r.until === T0 + 30 * DAY && r.days === 30, 'sovTiers off: the admin can buy Explorer (testing)', JSON.stringify(r));
r = await buyX('a@x.com', paid, T0); // tier missing = weekly
ok(r.ok && r.tier === 'weekly' && r.until === T0 + 7 * DAY && r.days === 7, 'tier missing = weekly: 500 credits, 7 days, as before', JSON.stringify(r));
@@ -172,7 +173,7 @@ async function buyX(email, payer, now, tier, opts) {
ok(!passes.get('m@x.com'), 'refused Sovereign/Legend buys write nothing', '');
v = gp.view('m@x.com', T0); ok(v.passes.map(x => x.tier).join() === 'weekly' && !v.tierPreview, 'sovTiers off: the member still sees only the weekly pass', JSON.stringify(v.passes.map(x => x.tier)));
charged = null; r = await buyX('m@x.com', spy, T0); ok(r.ok && r.tier === 'weekly' && charged.price === 500 && charged.label === 'Game Pass (7 days)' && r.until === T0 + 7 * DAY, 'sovTiers off: the weekly Game Pass sells exactly as before', JSON.stringify(charged));
charged = null; r = await buyX('adm@x.com', spy, T0, 'legend', { admin: true });
charged = null; r = await buyX('adm@x.com', spy, T0, 'legend', { preview: true });
ok(r.ok && r.tier === 'legend' && r.days === 365 && r.until === T0 + 365 * DAY && charged.price === 24999 && charged.label === 'Legend pass (365 days)', 'sovTiers off: the admin can buy Legend (testing): 24999 credits, 365 days', JSON.stringify({ r, charged }));
SC.sovTiers = '1';
// buy with enough purchased credits
+20 -3
View File
@@ -4085,7 +4085,8 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/my/gamepass' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
return json(res, 200, gamepass.view(s.email, gpDevNow(u.searchParams.get('devDay')), { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL }));
// 2026-10-25 (Marty): the member card shows every account exactly what a member sees, the admin's included; tier testing lives in Admin > Game Pass
return json(res, 200, gamepass.view(s.email, gpDevNow(u.searchParams.get('devDay'))));
}
if (p === '/api/my/gamepass/buy' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
@@ -4093,10 +4094,26 @@ const server = http.createServer(async (req, res) => {
const b = await readBody(req);
// 2026-10-22 (Marty): no pass is ever bought with credits. Buy only opens a waiting order; a FRESH package purchase of at least the
// tier price, by one of this member's own positions, fulfils it (gamepass.onEvent), so the sponsor and team are paid as usual.
// tier: weekly (missing) | explorer | champion | sovereign | legend; every tier above weekly is refused unless sovTiers is on, except for the ADMIN_EMAIL account (testing)
const r = gamepass.buy(s.email, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
// tier: weekly (missing) | explorer | champion | sovereign | legend; every tier above weekly is refused unless sovTiers is on, for every
// account (2026-10-25: the admin tests hidden tiers from Admin > Game Pass, POST /api/admin/gamepass/test-buy, not from the member card)
const r = gamepass.buy(s.email, gpDevNow(b.devDay), b.tier);
return json(res, r.error ? 400 : 200, r);
}
// 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).
// Always the signed-in admin's own account (the bearer password falls back to ADMIN_EMAIL); never another member's.
if (p.startsWith('/api/admin/gamepass/') && ['/api/admin/gamepass/preview', '/api/admin/gamepass/test-buy', '/api/admin/gamepass/test-cancel', '/api/admin/gamepass/test-comp'].includes(p)) {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const as = adminFromRequest(req); const me = String((as && as.email) || ADMIN_EMAIL || '').trim().toLowerCase();
if (!me) return json(res, 400, { error: 'No admin account email (ADMIN_EMAIL) is set.' });
if (p === '/api/admin/gamepass/preview' && req.method === 'GET') return json(res, 200, Object.assign({ email: me, test: true }, gamepass.view(me, gpDevNow(u.searchParams.get('devDay')), { preview: true })));
if (req.method === 'POST') {
const b = await readBody(req); const tier = String(b.tier || 'weekly').toLowerCase(); if (!gamepass.TIERS.includes(tier)) return json(res, 400, { error: 'unknown tier' });
if (p === '/api/admin/gamepass/test-buy') { const r = gamepass.buy(me, gpDevNow(b.devDay), tier, { preview: true }); if (!r.error) console.log('gamepass admin test order', tier, me); return json(res, r.error ? 400 : 200, Object.assign({ email: me, test: true }, r)); }
if (p === '/api/admin/gamepass/test-cancel') { const r = gamepass.cancelOrder(me, tier); if (r.order) console.log('gamepass admin test order cancelled', tier, me); return json(res, 200, Object.assign({ email: me }, r)); }
if (p === '/api/admin/gamepass/test-comp') { const r = gamepass.comp(me, 'admin tier test', tier); console.log('gamepass admin test comp', tier, me); return json(res, 200, Object.assign({ ok: true, email: me, test: true }, r)); }
}
}
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: /^0x[0-9a-f]{64}$/.test(String(b.tx || '')) ? b.tx : '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email, devMinedAt: Number(b.minedAt) || 0, devNow: Number(b.now) || 0 }) }); } // local tests only (minedAt fakes the block time, now the fulfilment time, tx replays a hash)
if (p === '/api/admin/gamepass/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.adminStats()); }
if (p === '/api/admin/gamepass/comp' && req.method === 'POST') { // support: give an account a pass week without a purchase