From 7f80d82486be12917a4814ffebf8a477075334c3 Mon Sep 17 00:00:00 2001 From: martbost Date: Sun, 25 Oct 2026 08:37:17 -0500 Subject: [PATCH] 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 --- docs/GAME-PASS.md | 4 +- gamepass.js | 28 +++++++++----- public/admin.html | 16 +++++++- public/assets/admin.js | 48 ++++++++++++++++++++++++ public/assets/my.js | 3 +- public/my.html | 2 +- qa/sov-passes-local.mjs | 81 ++++++++++++++++++++++++++++------------- qa/sov-passes-store.cjs | 7 ++-- server.js | 23 ++++++++++-- 9 files changed, 164 insertions(+), 48 deletions(-) diff --git a/docs/GAME-PASS.md b/docs/GAME-PASS.md index fb3e881..d07223d 100644 --- a/docs/GAME-PASS.md +++ b/docs/GAME-PASS.md @@ -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). diff --git a/gamepass.js b/gamepass.js index b5a44d7..095b2cb 100644 --- a/gamepass.js +++ b/gamepass.js @@ -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 }; diff --git a/public/admin.html b/public/admin.html index 8b92467..c0ff0cf 100644 --- a/public/admin.html +++ b/public/admin.html @@ -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} @@ -564,6 +572,10 @@

By pass tier

…
+
+

Tier test and preview

admin only · your own account
+
…
+

Pass sales

…
@@ -572,7 +584,7 @@

Comp a pass

support: one pass period, recorded as no sale

-

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 › 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.

+

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 › 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.