Pass tiers restructure (Dallas, Marty approved 2026-10-22): Explorer $19.99 (1999 credits) and Champion $39.99 (3999) for 30 days, new Sovereign $99.99 (9999, 30 days) and Legend $249.99 (24999, 365 days, the yearly pass). One table (gamepass.js TIER_DEFS: rank, names, settings stem, defaults, member-card perks); settings gamePassSovereign*/gamePassLegend* with kill switches; flag()/partner player/hand-off token carry sovereign/legend; buy, waiting orders ($100/$250 package copy), extend from max(now, until), comp/revoke, admin By pass tier table and comp options; chatbot tier fact says coming soon while sovTiers is off. All behind sovTiers (still 0): weekly Game Pass price, length and caps unchanged. Tests: sov-passes store + local extended (all pass), member QA 0 bugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 10:26:58 -05:00
parent 32eefae473
commit 839c867595
11 changed files with 259 additions and 77 deletions
+14 -2
View File
@@ -19,9 +19,10 @@ const kbSeed = require('./kb-seed');
let DATA_DIR = null;
let chain = null;
let PASS_TIERS = null; // () => the live pass tiers (server.js, from gamepass.cfg): the tier fact follows the sovTiers switch
const MODEL = process.env.OPENROUTER_MODEL || 'deepseek/deepseek-v4-flash:nitro';
function init(opts) { DATA_DIR = opts.dataDir; chain = opts.chain; return kb.init({ dataDir: DATA_DIR, seeds: seeds() }); }
function init(opts) { DATA_DIR = opts.dataDir; chain = opts.chain; PASS_TIERS = typeof opts.passTiers === 'function' ? opts.passTiers : null; return kb.init({ dataDir: DATA_DIR, seeds: seeds() }); }
function key() {
if (process.env.OPENROUTER_API_KEY) return process.env.OPENROUTER_API_KEY.trim();
try { return fs.readFileSync(path.join(DATA_DIR, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; }
@@ -187,11 +188,22 @@ function seeds() {
}
// ---- facts for the AI fallback ----
// PASS TIERS (2026-10-22): the passes above the weekly Game Pass (Explorer, Champion, Sovereign, Legend; names from gamepass.js
// TIER_DEFS). While sovTiers is off the assistant only says they are coming soon; once on, it quotes the live prices and contents.
function passTiersFact() {
let t = null; try { t = PASS_TIERS ? PASS_TIERS() : null; } catch (e) { t = null; }
const soon = '- MORE GAME PASSES: monthly and yearly passes for Shards of Valor are COMING SOON and are not on sale yet. If someone asks about them (or about an Explorer, Champion, Sovereign or Legend pass, or a monthly or yearly pass), say they are coming soon and that the $5 weekly Game Pass is the pass on sale today. Never quote their prices, contents or a launch date.\n';
if (!t || !t.on) return soon;
const rows = (t.rows || []).filter(r => r.sale);
if (!rows.length) return soon;
return '- GAME PASS TIERS (on sale, Members > Games > Game Pass at https://instantadpay.com/my#games): beside the $5 weekly Game Pass, ' + rows.map(r => r.name + ' $' + r.usd + ' for ' + r.days + ' days (' + r.price + ' purchased credits): ' + r.perks.join('; ')).join(' | ')
+ '. Each higher pass includes everything below it. Every pass is a Game Pass in all nine games with the SAME daily POL caps (1.50 / 5 POL): a higher pass never pays more POL. Passes run side by side, each with its own end date; no auto-renew; buying again adds the pass length from its end date (or from now if it ended). Paid with purchased credits only; with none, a package of at least the price starts the pass when it settles. Nothing earned in a game is taken away when a pass ends.\n';
}
function systemPrompt(kbBlock) {
return `You are the assistant on InstantAdPay (https://instantadpay.com), a membership advertising platform.
FACTS:
- ROAD AGENT (LIVE 2026-10-15, https://roadagent.app): a night-highway shooter open to every member. Open the Games tab and tap Play on the Road Agent card, or go to roadagent.app and sign in with the InstantAdPay email. Drive the four-lane highway, shoot the hostiles (thug sedans, switchblades, gunner vans), spare the civilians, pull into the weapons truck for oil slicks, smoke and missiles. Clearing a sector for the first time pays POL to the wallet on the member's InstantAdPay account, plus a daily patrol reward; scrap buys garage upgrades. Fuel = a sponsor visit: before a run the player visits an advertiser's page (a FUEL STOP), which is a normal verified visit with the dwell timer and human check, charged to the advertiser like any visit; advertisers' existing visits campaigns are already in the rotation, nothing to set up; to get more traffic from the game, top up the visits campaign. Clickable Pause, Sound and Music buttons sit under the game (P / M / N keys also work), and the Run tab has an Invite a friend card with the member's roadagent.app/?ref=<username> link.
${passTiersFact()}- ROAD AGENT (LIVE 2026-10-15, https://roadagent.app): a night-highway shooter open to every member. Open the Games tab and tap Play on the Road Agent card, or go to roadagent.app and sign in with the InstantAdPay email. Drive the four-lane highway, shoot the hostiles (thug sedans, switchblades, gunner vans), spare the civilians, pull into the weapons truck for oil slicks, smoke and missiles. Clearing a sector for the first time pays POL to the wallet on the member's InstantAdPay account, plus a daily patrol reward; scrap buys garage upgrades. Fuel = a sponsor visit: before a run the player visits an advertiser's page (a FUEL STOP), which is a normal verified visit with the dwell timer and human check, charged to the advertiser like any visit; advertisers' existing visits campaigns are already in the rotation, nothing to set up; to get more traffic from the game, top up the visits campaign. Clickable Pause, Sound and Music buttons sit under the game (P / M / N keys also work), and the Run tab has an Invite a friend card with the member's roadagent.app/?ref=<username> link.
- HELP DESK (LIVE 2026-10-16): members open Help in the dashboard (/my#help) to send Marty a support ticket (pick a category, a subject, the message, up to 2 screenshots), see each ticket's status (Open, Waiting on you, Closed) and read and answer his replies; a badge shows when he has replied, and replies also arrive by email. Anyone signed out or locked out uses the public form at https://instantadpay.com/support (name, email, category, subject, message) and gets an email with the ticket number (like IAP-1042) and a private link to view and reply, no sign-in needed. support@instantadpay.com also reaches Marty. Replying to a closed ticket opens it again. In this chat, "Send this to support" turns the conversation into a ticket. Only Marty answers, so replies are not instant; never promise a response time.
- PRESENTATION (2026-10-15): instantadpay.com/presentation is a public page (no sign-in) with the narrated InstantAdPay presentation, about six minutes, Marty's voice, captions in 6 languages (English, Italiano, Français, Español, Deutsch, Português) chosen with pills under the player. Sixteen parts: the platform, ad reach, the nine games that pay POL, the $20 split ($10 / $4 / $2 / $4 platform, same transaction), three rules, packages, the 2-then-5 unlock, pass-up, wide versus narrow ($800 vs $36, an illustration), Qualified Start, the Pipeline, LinkSpin (pre-launch Nov 1), one wallet across the network, the first week, and 'the target is five'. Share link: Members > Promo tools > 'Share the presentation' copies instantadpay.com/presentation?ref=<username>; ?ref sets the same 30-day sponsor cookie as the invite link, the page shows 'Shared with you by @name' with avatar and a Join button to /join/<username>. It is in the site menu as 'Presentation'. BUILD WIDE VIDEO: first card in Promo tools > Videos ('Build wide: watch the payments flow'), matched link ?v=wide.
- WIRED WEDNESDAY: every Wednesday, Central time (midnight to midnight), any ad package of $20 or more (Activation and up; no $10 pack exists) earns +25% bonus credits wired into the buyer's balance the moment the purchase settles, purchased-grade (usable on every format incl. login ads), credit log label "Wired Wednesday". First one: Wednesday 2026-09-30. Page: instantadpay.com/wednesday. Credits buy ad delivery, never money.
+42 -23
View File
@@ -215,33 +215,52 @@ sales. If the POL rate is unavailable the tick retries next hour.
- Settings pass through `/api/admin/site` like every other site setting (that endpoint accepts any key; the defaults above make the
Game Pass keys show in the Site settings form).
## Pass tiers: Explorer and Champion (IAP side, 2026-10-18)
## Pass tiers: Explorer, Champion, Sovereign, Legend (IAP side, 2026-10-18; restructured 2026-10-22)
Spec: `ultima-rpg/docs/IAP-PASSES-SPEC.md`. Marty approved the safe form: paid tiers add Shards of Valor islands and looks, never
power, never more POL. The weekly pass is unchanged.
Spec: `ultima-rpg/docs/IAP-PASSES-SPEC.md`. Marty approved the safe form on 2026-10-18 (never more POL) and Dallas's new structure
on 2026-10-22 (prices below, plus Sovereign and the yearly Legend). The weekly pass is unchanged. Everything above weekly stays
switched off for members (`sovTiers` 0) until Marty flips it.
- **Tiers**: `weekly` (500 credits, 7 days), `explorer` (2000, 30 days), `champion` (4000, 30 days). Every tier is a Game Pass
holder everywhere with exactly the pass caps; `polgrant` keeps answering `pass: true` (a boolean).
- **Store**: `record.tiers = { weekly: { until }, explorer: { until }, champion: { until } }`, the legacy `until` mirrors the weekly
tier, bought rows carry `tier` (missing = weekly), waiting orders carry `tier` (missing = weekly). Lazy migration: a record
without `tiers` reads its `until` as the weekly tier.
- **Wire**: `flag()` = `{ active, until, tier, tiers }` (`tier` = highest active, `until` = that tier's end). The hand-off token
carries `gamePass: { active, until, tier }`; `GET /api/partner/player` carries `pass: { active, until, tier, tiers }`.
- **Buy**: `POST /api/my/gamepass/buy { tier }` (missing = weekly). Explorer/Champion need `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
| Tier | Name | Price | Length | In Shards of Valor (each includes everything below) |
|---|---|---|---|---|
| `weekly` | Game Pass | 500 credits ($5) | 7 days | the Game Pass in all nine games, the Sunless Vault, weapons unlocked |
| `explorer` | Explorer | 1999 ($19.99) | 30 days | weapons, gear, 2 DLC islands |
| `champion` | Champion | 3999 ($39.99) | 30 days | weapons, gear, 4 DLC islands of your choice, the Druid hero, level cap 30 |
| `sovereign` | Sovereign | 9999 ($99.99) | 30 days | weapons, gear, all DLC islands, the Necromancer hero, level cap 40 |
| `legend` | Legend | 24999 ($249.99) | 365 days | weapons, gear, all DLC islands, every hero including the Archer, level cap 40 |
- **One table**: `gamepass.js` `TIER_DEFS` holds the rank, wire key, display name, settings stem, default price/length and the
member-card list for every tier. Rename a tier there (the card, admin pane, charge label and chatbot all read it).
- **Rank**: weekly < explorer < champion < sovereign < legend. Every tier is a Game Pass holder everywhere with exactly the pass
caps; `polgrant` keeps answering `pass: true` (a boolean).
- **Store**: `record.tiers = { weekly: { until }, explorer: { until }, champion: { until }, sovereign: { until }, legend: { until } }`,
the legacy `until` mirrors the weekly tier, bought rows carry `tier` (missing = weekly), waiting orders carry `tier` (missing =
weekly). Lazy migration: a record without `tiers` reads its `until` as the weekly tier.
- **Wire**: `flag()` = `{ active, until, tier, tiers }` (`tier` = highest active, `until` = that tier's end; `tiers` has all five
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
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). There is no $40 package, so Champion's copy names the $50 one.
- **Renew / expiry**: no auto-renew, no proration. Buying again extends that tier from `max(now, until)`. Tiers run side by side;
when a higher one ends the next one shows through. Admin comp takes a tier; `POST /api/admin/gamepass/revoke { email, tier, why }`
ends one tier now (support refunds only, credits are not returned by it).
- **Tournament**: any tier holds a seat; only weekly sales feed the pool unless `passTournamentTierSales` is `1`.
- **Settings**: `sovTiers` 0, `gamePassExplorerEnabled` 1 / `gamePassChampionEnabled` 1 (a `0` stops one tier),
`gamePassExplorerPriceCredits` 2000, `gamePassChampionPriceCredits` 4000, `gamePassExplorerDays` / `gamePassChampionDays` 30,
`passTournamentTierSales` 0.
- **Member UI**: the Games tab card shows the three tiers side by side (end dates in Central time); `/my#passes` opens it (the
each tx once). Copy names the package that covers the price: $20 (Explorer), $50 (Champion, there is no $40 one), $100
(Sovereign), $250 (Legend).
- **Renew / expiry**: no auto-renew, no proration. Buying again extends that tier from `max(now, until)` by its length (Legend: 365
days). Tiers run side by side; when a higher one ends the next one shows through. Admin comp takes a tier;
`POST /api/admin/gamepass/revoke { email, tier, why }` ends one tier now (support refunds only, credits are not returned by it).
- **Tournament**: any tier holds a seat; only weekly sales feed the pool unless `passTournamentTierSales` is `1` (then every tier's
sales do).
- **Settings** (defaults): `sovTiers` 0; kill switches `gamePassExplorerEnabled` / `gamePassChampionEnabled` /
`gamePassSovereignEnabled` / `gamePassLegendEnabled` 1 (a `0` stops one tier); `gamePassExplorerPriceCredits` 1999,
`gamePassChampionPriceCredits` 3999, `gamePassSovereignPriceCredits` 9999, `gamePassLegendPriceCredits` 24999;
`gamePassExplorerDays` / `gamePassChampionDays` / `gamePassSovereignDays` 30, `gamePassLegendDays` 365;
`passTournamentTierSales` 0. A value saved in the site settings file wins over these defaults.
- **Chatbot**: while `sovTiers` is off the assistant only says more passes are coming soon (no prices, no contents, no date); once
on, its fact lists each tier on sale with the live price, length and contents.
- **Member UI**: the Games tab card shows the tiers side by side (end dates in Central time); `/my#passes` opens it (the
Shards of Valor Buy button). **Admin**: Game Pass pane "By pass tier" table, comp per tier, end-a-tier button.
- **Tests**: `bash qa/run.sh sov-passes` (store unit checks + a local copy where the admin buys Explorer through the real
`ads.gamePurchase(purchasedOnly)` path with credits seeded by `qa/sov-passes-stub.cjs`).
- **Tests**: `bash qa/run.sh sov-passes` (store unit checks + a local copy where the admin buys Explorer and Sovereign through the
real `ads.gamePurchase(purchasedOnly)` path with credits seeded by `qa/sov-passes-stub.cjs`, and a Legend order is fulfilled by
a $250 package).
## Games: as built (2026-10-16, local commits only, nothing deployed)
+35 -16
View File
@@ -20,6 +20,9 @@
// `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
// extends that tier from max(now, until).
// 2026-10-22 (Dallas's structure, Marty approved): Explorer $19.99 and Champion $39.99 (30 days), plus Sovereign $99.99 (30 days)
// and Legend $249.99 (365 days, the yearly pass), all in TIER_DEFS below and all behind the same sovTiers switch. The weekly
// pass is unchanged ($5 / 7 days / the same caps). Rank weekly < explorer < champion < sovereign < legend.
'use strict';
const fs = require('fs');
const path = require('path');
@@ -29,8 +32,26 @@ const GAMES = ['polhunter', 'gemkingdom', 'spellwheel', 'spookydoors', 'polywarr
const NAMES = { polhunter: 'PolHunter', gemkingdom: 'Gem Kingdom', spellwheel: 'SpellWheel', spookydoors: 'Spooky Doors', polywarriors: 'PolyWarriors', clutterhunt: 'ClutterHunt', polybreak: 'PolyBreak', driprunner: 'Drip Runner', roadagent: 'Road Agent', shardsofvalor: 'Shards of Valor' };
const SHARES = [0.5, 0.3, 0.2]; // tournament prize split, places 1-3
const KEEP_DAYS = 90; // answered refs and day rows are kept this long (idempotency window)
const TIERS = ['weekly', 'explorer', 'champion']; // lowest to highest
const TIER_NAMES = { weekly: 'Game Pass', explorer: 'Explorer', champion: 'Champion' };
// THE pass table (2026-10-22, Dallas's structure, Marty approved): lowest to highest, a higher tier includes everything below.
// Rename a tier here (name) and nowhere else: the member card, the admin pane, the charge label and the chatbot read it from here.
// key = the wire value the games read (flag().tier / tiers); set = the Admin > Settings stem (gamePass<set>Enabled /
// PriceCredits / Days; weekly keeps its original gamePassPriceCredits / gamePassDays); price = purchased-grade credits (100 = $1);
// perks = what the member card lists. Every tier is a Game Pass holder everywhere with the SAME caps (no extra POL).
const TIER_DEFS = [
{ key: 'weekly', name: 'Game Pass', set: '', price: 500, days: 7,
perks: ['Higher daily POL caps in every game', 'A seat in the weekly Pass Tournament', 'Extra plays and a perk in each game', 'Shards of Valor: the Sunless Vault and weapons unlocked'] },
{ key: 'explorer', name: 'Explorer', set: 'Explorer', price: 1999, days: 30,
perks: ['Everything in the Game Pass, in every game', 'Shards of Valor: weapons and gear unlocked', 'Shards of Valor: 2 bonus islands'] },
{ key: 'champion', name: 'Champion', set: 'Champion', price: 3999, days: 30,
perks: ['Everything in Explorer', 'Shards of Valor: 4 bonus islands of your choice', 'Shards of Valor: the Druid hero', 'Shards of Valor: level cap 30'] },
{ key: 'sovereign', name: 'Sovereign', set: 'Sovereign', price: 9999, days: 30,
perks: ['Everything in Champion', 'Shards of Valor: every bonus island', 'Shards of Valor: the Necromancer hero', 'Shards of Valor: level cap 40'] },
{ key: 'legend', name: 'Legend', set: 'Legend', price: 24999, days: 365,
perks: ['Everything in Sovereign, for a full year', 'Shards of Valor: every bonus island', 'Shards of Valor: every hero, the Archer included', 'Shards of Valor: level cap 40'] },
];
const TIERS = TIER_DEFS.map(d => d.key); // lowest to highest
const TIER_NAMES = Object.fromEntries(TIER_DEFS.map(d => [d.key, d.name]));
const TIER_DEF = Object.fromEntries(TIER_DEFS.map(d => [d.key, d]));
const tierOk = t => TIERS.includes(t);
const rowTier = b => (b && tierOk(b.tier)) ? b.tier : 'weekly'; // bought rows before 2026-10-18 have no tier: weekly
const r6 = x => Math.round((Number(x) || 0) * 1e6) / 1e6;
@@ -63,14 +84,12 @@ function cfg() {
return {
enabled: on('gamePassEnabled'),
price, days,
// per tier: price in purchased-grade credits (100 = $1), length, and whether it is on sale. Explorer/Champion need the master
// switch sovTiers AND the weekly pass switched on; their own gamePass<Tier>Enabled is a kill switch (missing = on).
// per tier: price in purchased-grade credits (100 = $1), length, and whether it is on sale. Every tier above weekly needs the
// master switch sovTiers AND the weekly pass switched on; its own gamePass<Set>Enabled is a kill switch (missing = on).
tierSales: on('sovTiers'),
tiers: {
weekly: { price, days, sale: on('gamePassEnabled') },
explorer: { price: Math.max(1, Math.round(n('gamePassExplorerPriceCredits', 2000))), days: Math.max(1, Math.round(n('gamePassExplorerDays', 30))), sale: on('gamePassEnabled') && on('sovTiers') && !offExplicit('gamePassExplorerEnabled') },
champion: { price: Math.max(1, Math.round(n('gamePassChampionPriceCredits', 4000))), days: Math.max(1, Math.round(n('gamePassChampionDays', 30))), sale: on('gamePassEnabled') && on('sovTiers') && !offExplicit('gamePassChampionEnabled') },
},
tiers: Object.fromEntries(TIER_DEFS.map(d => [d.key, d.key === 'weekly' ? { price, days, sale: on('gamePassEnabled') }
: { price: Math.max(1, Math.round(n('gamePass' + d.set + 'PriceCredits', d.price))), days: Math.max(1, Math.round(n('gamePass' + d.set + 'Days', d.days))),
sale: on('gamePassEnabled') && on('sovTiers') && !offExplicit('gamePass' + d.set + 'Enabled') }])),
tournamentTierSales: on('passTournamentTierSales'), // off: only weekly pass sales feed the Pass Tournament pool (exactly as before tiers)
free: { daily: Math.max(0, n('capFreeDaily', 0.30)), total: Math.max(0, n('capFreeTotal', 2.0)) },
pass: { daily: Math.max(0, n('capPassDaily', 1.50)), total: Math.max(0, n('capPassTotal', 5.0)) },
@@ -150,20 +169,20 @@ 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 Explorer/Champion while sovTiers is off
// 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'));
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 Explorer/Champion while sovTiers is off).
// GET /api/my/gamepass. opts.admin = the ADMIN_EMAIL account (sees every tier 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 caps = capsFor(e, t);
// the tier rows this member sees: weekly always; Explorer/Champion 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, to the admin, 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], price: tc.price, usd: tc.price / 100, days: tc.days, package: packageFor(tc.price / 100),
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) };
});
const tiered = passRows.some(r => r.tier !== 'weekly');
@@ -290,13 +309,13 @@ function voidGrant(o) {
// ---- the weekly Pass Tournament (Monday 9 AM Central, the week that just closed) ----
function nextTournamentAt(now) { const t = now || Date.now(); const ws = weekStart(t); const thisMon = ws + 9 * 3600000; return t < thisMon ? thisMon : ws + 7 * 86400000 + 9 * 3600000; }
function holdersIn(start, end) { // any tier holds a Pass Tournament seat (Explorer and Champion include everything Weekly gives)
function holdersIn(start, end) { // any tier holds a Pass Tournament seat (every tier above weekly includes everything Weekly gives)
const out = [];
for (const [e, p] of passes) { if (!p || !(Math.max(...TIERS.map(k => tiersOf(p)[k])) > start)) continue; if ((p.bought || []).some(b => b.ts < end)) out.push(e); }
return out;
}
const isSale = b => b && b.via !== 'admin'; // comps are passes, not sales
// the pool counts weekly pass sales only, unless passTournamentTierSales adds Explorer/Champion sales (default off: the pool exactly as before tiers)
// the pool counts weekly pass sales only, unless passTournamentTierSales adds the sales of every tier above weekly (default off: the pool exactly as before tiers)
function salesIn(start, end, withTiers) { let n = 0, usd = 0; for (const [, p] of passes) for (const b of (p && p.bought) || []) if (isSale(b) && b.ts >= start && b.ts < end && (withTiers || rowTier(b) === 'weekly')) { n += 1; usd += Number(b.usd) || 0; } return { n, usd: Math.round(usd * 100) / 100 }; }
function scoresFor(wk, emails) {
return emails.map(e => { const M = L.members[e]; const g = (M && M.weeks[wk]) || {}; const score = Object.values(g).reduce((n, x) => n + x, 0); const first = ((passes.get(e) || {}).bought || []).reduce((m, b) => Math.min(m, b.ts), Infinity);
@@ -422,5 +441,5 @@ function prune(now) {
return n;
}
module.exports = { init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, 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, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey,
_ledger: () => L };
+3 -3
View File
@@ -554,9 +554,9 @@
</div>
<div class="card">
<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></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>
<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">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. Monthly tiers: sovTiers (1/0, the Explorer + Champion sale switch; off = only the admin account sees them), gamePassExplorerEnabled / gamePassChampionEnabled (0 stops one tier), gamePassExplorerPriceCredits (2000), gamePassChampionPriceCredits (4000), gamePassExplorerDays / gamePassChampionDays (30), 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">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>
</div>
<div class="pane" id="pane-settings" hidden>
@@ -602,6 +602,6 @@
<script src="/assets/common.js?v=20261016n"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/admin-kb.js?v=20261020kb"></script>
<script src="/assets/admin.js?v=20261020kb"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
<script src="/assets/admin.js?v=20261022gpt"></script><script src="/assets/admin-sponsorcheck.js?v=20261022sc"></script>
</body>
</html>
+3 -3
View File
@@ -1168,10 +1168,10 @@
+ (Q.byGame && Object.keys(Q.byGame).length ? '<p class="muted" style="margin:8px 0 0">By game: ' + Object.entries(Q.byGame).filter(([k]) => !k.startsWith('plays:')).map(([k, v]) => esc(k) + ' ' + pol(v) + ' POL queued').concat(Object.entries(Q.byGame).filter(([k]) => k.startsWith('plays:')).map(([k, v]) => esc(k.slice(6)) + ' ' + v + ' plays')).join(' · ') + '</p>' : '');
// per tier (2026-10-18): active counts each account once, at its highest tier; Central week / month
const TS = r.tiers || {}, TC = S.tiers || {};
$('gpTiersSub').textContent = 'Explorer + Champion sale: ' + (r.tierSales ? 'ON' : 'OFF (admin preview only)') + ' · ' + (r.week ? r.week.label : '') + ' · month ' + (r.month ? r.month.label : '') + ' · tournament pool ' + (S.tournamentTierSales ? 'includes' : 'excludes') + ' monthly sales';
$('gpTiersSub').textContent = 'Tiers above weekly, sale: ' + (r.tierSales ? 'ON' : 'OFF (admin preview only)') + ' · ' + (r.week ? r.week.label : '') + ' · month ' + (r.month ? r.month.label : '') + ' · tournament pool ' + (S.tournamentTierSales ? 'includes' : 'excludes') + ' tier sales';
$('gpTiers').innerHTML = '<table class="adm-table"><tr><th>Tier</th><th>Price</th><th class="num">Active</th><th class="num">Sold week</th><th class="num">Sold month</th><th class="num">All time</th><th class="num">Renewals 30d</th><th class="num">Ending in 7 days</th><th class="num">Comped</th><th class="num">Waiting</th></tr>'
+ ['weekly', 'explorer', 'champion'].map(k => { const x = TS[k] || {}, c = TC[k] || {}; return '<tr><td style="white-space:nowrap">' + esc(x.name || k) + (c.sale ? '' : '<br><span class="chip flat">not on sale</span>') + '</td><td style="white-space:nowrap">' + (c.price || 0) + ' cr · ' + (c.days || 0) + ' d</td><td class="num">' + (x.active || 0) + '</td><td class="num">' + (x.soldWeek || 0) + ' · ' + usd(x.usdWeek) + '</td><td class="num">' + (x.soldMonth || 0) + ' · ' + usd(x.usdMonth) + '</td><td class="num">' + (x.soldTotal || 0) + ' · ' + usd(x.usdTotal) + '</td><td class="num">' + (x.renewals30d || 0) + '</td><td class="num">' + (x.expiring7d || 0) + '</td><td class="num">' + (x.comped || 0) + '</td><td class="num">' + (x.waitingOrders || 0) + '</td></tr>'; }).join('')
+ '</table><p class="muted" style="margin:8px 0 0">Every tier gets the same pass caps (no extra POL). Monthly tiers add Shards of Valor islands and looks only.</p>';
+ (Object.keys(TS).length ? Object.keys(TS) : ['weekly', 'explorer', 'champion', 'sovereign', 'legend']).map(k => { const x = TS[k] || {}, c = TC[k] || {}; return '<tr><td style="white-space:nowrap">' + esc(x.name || k) + (c.sale ? '' : '<br><span class="chip flat">not on sale</span>') + '</td><td style="white-space:nowrap">' + (c.price || 0) + ' cr<br>' + (c.days || 0) + ' d</td><td class="num">' + (x.active || 0) + '</td><td class="num">' + (x.soldWeek || 0) + ' · ' + usd(x.usdWeek) + '</td><td class="num">' + (x.soldMonth || 0) + ' · ' + usd(x.usdMonth) + '</td><td class="num">' + (x.soldTotal || 0) + ' · ' + usd(x.usdTotal) + '</td><td class="num">' + (x.renewals30d || 0) + '</td><td class="num">' + (x.expiring7d || 0) + '</td><td class="num">' + (x.comped || 0) + '</td><td class="num">' + (x.waitingOrders || 0) + '</td></tr>'; }).join('')
+ '</table><p class="muted" style="margin:8px 0 0">Every tier gets the same pass caps (no extra POL). Each higher tier includes everything below it and adds Shards of Valor content (Legend is yearly).</p>';
$('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>'
+11 -8
View File
@@ -1727,12 +1727,15 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
const gpPol = n => Number(n || 0).toFixed(2).replace(/\.?0+$/, '');
// Pass tiers (2026-10-18, Marty approved the safe form): weekly Game Pass, monthly Explorer and Champion side by side. Paid tiers add
// islands and looks in Shards of Valor, never power and never more POL; the main story is free. End dates in Central time.
// 2026-10-22 (Dallas's structure): + Sovereign (monthly) and Legend (yearly). Names and what each includes come from the server
// (gamepass.js TIER_DEFS, row.perks); GP_TIER_PERKS is only the fallback for an older server answer.
const gpCT = ms => new Date(Number(ms)).toLocaleDateString('en-US', { timeZone: 'America/Chicago', weekday: 'short', month: 'short', day: 'numeric' }) + ' (Central)';
const GP_TIER_PERKS = {
weekly: ['Higher daily POL caps in every game', 'A seat in the weekly Pass Tournament', 'Extra plays and a perk in each game', 'Shards of Valor: the Sunless Vault and the Weekly look'],
explorer: ['Everything in the Game Pass, in every game', 'Shards of Valor: up to 4 bonus islands you pick (1 swap a month)', 'Explorer outfits and gear styles for your character'],
champion: ['Everything in Explorer', 'Shards of Valor: every bonus island, now and future', 'Champion outfits and gear styles for your character'],
};
const gpLen = d => d >= 365 && d % 365 === 0 ? (d === 365 ? '1 year' : (d / 365) + ' years') : d + ' days';
function renderPassTiers(card, gp, highlight) {
const rows = gp.passes || []; const top = rows.find(r => r.tier === gp.tier);
const state = top ? '<span class="badge" style="background:var(--gold,#e2b04a);color:#111">' + esc(top.name) + ' active · until ' + esc(gpCT(top.until)) + '</span>'
@@ -1741,25 +1744,25 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
const capsLine = caps.enforced ? 'Today: <b>' + gpPol(caps.used && caps.used.total) + '</b> of ' + gpPol(caps.total) + ' POL used across the games (' + gpPol(caps.used && caps.used.daily) + ' of ' + gpPol(caps.daily) + ' on daily play).' : '';
const box = r => {
const btn = r.waiting ? '<button class="btn small" type="button" data-gp-go="1">Buy a $' + r.package + ' package</button>'
: r.open ? '<button class="btn small" type="button" data-gp-tier="' + esc(r.tier) + '">' + (r.active ? 'Extend ' + r.days + ' more days' : 'Get ' + esc(r.name)) + ' · ' + r.price + ' credits</button>'
: r.open ? '<button class="btn small" type="button" data-gp-tier="' + esc(r.tier) + '">' + (r.active ? 'Extend ' + gpLen(r.days) + ' more' : 'Get ' + esc(r.name)) + ' · ' + r.price + ' credits</button>'
: '<span class="small muted">Not on sale right now. Your pass keeps running.</span>';
return '<div class="gp-tier' + (r.tier === gp.tier ? ' on' : '') + '"><h4>' + esc(r.name) + '</h4>'
+ '<p class="gp-price">$' + r.usd + ' <span class="small muted">for ' + r.days + ' days</span></p>'
+ '<ul>' + (GP_TIER_PERKS[r.tier] || []).map(x => '<li>' + esc(x) + '</li>').join('') + '</ul>'
+ '<p class="gp-price">$' + r.usd + ' <span class="small muted">for ' + gpLen(r.days) + '</span></p>'
+ '<ul>' + (r.perks || GP_TIER_PERKS[r.tier] || []).map(x => '<li>' + esc(x) + '</li>').join('') + '</ul>'
+ '<p class="small" style="margin:6px 0">' + (r.active ? '<b>Active until ' + esc(gpCT(r.until)) + '</b>' : r.waiting ? 'Waiting for a $' + r.package + ' package' : 'Not active') + '</p>'
+ btn + '</div>';
};
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 or monthly · 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> Explorer and Champion are hidden from members until sovTiers is switched on in Settings.</p>' : '')
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. The monthly passes add islands to explore and looks in Shards of Valor. <b>Paid passes never make you stronger than players who earn their gear</b>, and they never pay more POL.</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 never make you stronger than players who earn their gear</b>, and they never pay more POL.</p>'
+ '<div class="gp-tiers">' + rows.map(box).join('') + '</div>'
+ (capsLine ? '<p class="small muted" style="margin-top:10px">' + capsLine + '</p>' : '')
+ '<p class="small muted" style="margin:10px 0 0">Paid with purchased credits from your packages (earned credits never buy a pass). Passes run side by side: a higher pass shows first, and the one underneath keeps its own end date. No auto-renew: buy again any time and that pass extends from its end date. When a pass ends, nothing you earned in a game is taken away.</p>';
card.querySelectorAll('[data-gp-tier]').forEach(b => b.addEventListener('click', async () => {
const r = rows.find(x => x.tier === b.dataset.gpTier); if (!r) return;
const yes = await IAP.confirmBox((r.active ? 'Extend your ' + r.name + ' by ' + r.days + ' days' : 'Get ' + r.name + ' for ' + r.days + ' days') + ' for ' + r.price + ' purchased credits ($' + r.usd + ')? It starts at once. Islands and looks only: no extra power, no extra POL.', { title: r.name, ok: r.active ? 'Extend' : 'Get ' + r.name, cancel: 'Not now' });
const yes = await IAP.confirmBox((r.active ? 'Extend your ' + r.name + ' by ' + gpLen(r.days) : 'Get ' + r.name + ' for ' + gpLen(r.days)) + ' for ' + r.price + ' purchased credits ($' + r.usd + ')? It starts at once. The same POL caps as every pass: no extra POL.', { title: r.name, ok: r.active ? 'Extend' : 'Get ' + r.name, cancel: 'Not now' });
if (!yes) return;
b.disabled = true;
try {
@@ -1797,7 +1800,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
const card = $('gpCard'); if (!card) return;
let gp = null; try { gp = await (await fetch('/api/my/gamepass')).json(); } catch (e) {}
if (!gp || !(gp.enabled || gp.show)) { card.hidden = true; return; }
if ((gp.passes || []).some(r => r.tier !== 'weekly')) return renderPassTiers(card, gp, highlight); // Explorer / Champion on sale (or admin preview, or a holder)
if ((gp.passes || []).some(r => r.tier !== 'weekly')) return renderPassTiers(card, gp, highlight); // a tier above weekly on sale (or admin preview, or a holder)
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
@@ -1188,7 +1188,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=20261022gpb"></script>
<script src="/assets/my.js?v=20261022gpt"></script>
<script src="/assets/chat.js?v=20261016n"></script>
</body>
</html>
+1 -1
View File
@@ -8,7 +8,7 @@
# bash qa/run.sh sponsorfollow # sponsor follow rule + network tank unit tests and the two-server e2e (local IAP + local LinkSpin, throwaway data)
# bash qa/run.sh door # Spooky Doors door + costume shop flows on their own local copy (qa/door.mjs boots it)
# bash qa/run.sh gamepass # Game Pass buy flow + account-wide POL caps (polgrant) on their own local copy (qa/gamepass.mjs boots it)
# bash qa/run.sh sov-passes # Explorer/Champion tiers: store unit checks + admin buys Explorer with seeded purchased credits on a local copy (screenshots D:/tmp/sov-passes)
# bash qa/run.sh sov-passes # pass tiers (Explorer/Champion/Sovereign/Legend): store unit checks + admin buys Explorer + Sovereign with seeded purchased credits on a local copy (screenshots D:/tmp/sov-passes)
# bash qa/run.sh gamepass-games # the REAL games' polgrant.js + PolHunter's tournament payer against a local copy (needs the sibling game repos)
# Each local run boots server.js on its own port with a throwaway data dir (JSON store, no DB, no
# mail key, devCode sign-in), so nothing touches production data. Reports land in qa/out/.
+41 -10
View File
@@ -6,6 +6,8 @@
// Explorer in the browser through the REAL ads.gamePurchase(purchasedOnly) charge; the 500 left is short for a second Explorer
// (waiting order, $20 package copy); the Shards of Valor hand-off token and GET /api/partner/player carry tier explorer;
// polgrant answers pass: true with the weekly pass caps; Admin > Game Pass shows the tier table. Exit 1 on any failure.
// 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.
import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
@@ -21,7 +23,7 @@ const B = 'http://127.0.0.1:' + PORT;
const SHOTS = process.env.SHOTS || 'D:/tmp/sov-passes'; fs.mkdirSync(SHOTS, { recursive: true });
const SOV = crypto.randomBytes(24).toString('hex'); // throwaway, never printed
const ADMIN_PW = 'localtest', ADMIN_EMAIL = 'qa-admin@example.com', MEMBER = 'qa-sov-member@example.com';
const SEED_ID = 9001, SEED_CREDITS = 2500;
const SEED_ID = 9001, SEED_CREDITS = 1999 + 9999 + 500; // Explorer + Sovereign, then 500 left (short for a second Explorer)
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-sovpasses-')); fs.mkdirSync(path.join(DATA, 'uploads'));
let fails = 0; const ok = (c, label, extra) => { console.log((c ? 'PASS ' : 'FAIL ') + label + (extra ? ' ' + extra : '')); if (!c) fails++; };
const hide = page => page.evaluate(() => { document.querySelectorAll('.lgate,.iap-welcome,#onboardModal').forEach(m => m.hidden = true); });
@@ -70,7 +72,8 @@ try {
ok(up && /qa stub: position #9001/.test(srvLog), 'local copy up with the seeded position', '');
await api('/api/admin/site', { method: 'PATCH', data: { fraudMaxSignupsPerIpDay: 10, gamePassEnabled: '1' } }, adminH);
const site = (await api('/api/admin/site', null, adminH)).j; const sc = (site && (site.site || site)) || {};
ok(sc.sovTiers === '0' && Number(sc.gamePassExplorerPriceCredits) === 2000 && Number(sc.gamePassChampionPriceCredits) === 4000 && Number(sc.gamePassExplorerDays) === 30 && sc.passTournamentTierSales === '0', 'defaults: sovTiers 0, Explorer 2000 / Champion 4000 credits, 30 days, passTournamentTierSales 0', JSON.stringify({ sovTiers: sc.sovTiers, e: sc.gamePassExplorerPriceCredits, c: sc.gamePassChampionPriceCredits }));
ok(sc.sovTiers === '0' && Number(sc.gamePassExplorerPriceCredits) === 1999 && Number(sc.gamePassChampionPriceCredits) === 3999 && Number(sc.gamePassExplorerDays) === 30 && sc.passTournamentTierSales === '0', 'defaults: sovTiers 0, Explorer 1999 / Champion 3999 credits, 30 days, passTournamentTierSales 0', JSON.stringify({ sovTiers: sc.sovTiers, e: sc.gamePassExplorerPriceCredits, c: sc.gamePassChampionPriceCredits }));
ok(Number(sc.gamePassSovereignPriceCredits) === 9999 && Number(sc.gamePassSovereignDays) === 30 && sc.gamePassSovereignEnabled === '1' && Number(sc.gamePassLegendPriceCredits) === 24999 && Number(sc.gamePassLegendDays) === 365 && sc.gamePassLegendEnabled === '1' && Number(sc.gamePassPriceCredits) === 500 && Number(sc.gamePassDays) === 7, 'defaults: Sovereign 9999 / 30 days, Legend 24999 / 365 days (kill switches 1), weekly 500 / 7 unchanged', JSON.stringify({ s: [sc.gamePassSovereignPriceCredits, sc.gamePassSovereignDays], l: [sc.gamePassLegendPriceCredits, sc.gamePassLegendDays] }));
const hA = await signIn(ADMIN_EMAIL, 'qaadmin'), hM = await signIn(MEMBER, 'qasovm');
// 1. a member with sovTiers off: weekly only, Explorer refused
@@ -78,20 +81,24 @@ try {
ok(g.passes && g.passes.length === 1 && g.passes[0].tier === 'weekly' && !g.tierPreview, 'member, sovTiers off: only the weekly pass is offered', JSON.stringify((g.passes || []).map(x => x.tier)));
let r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hM);
ok(r.status === 400 && r.j.error === 'The Explorer pass is not open yet.', 'member, sovTiers off: Explorer buy refused', JSON.stringify(r.j));
for (const [tier, name] of [['sovereign', 'Sovereign'], ['legend', 'Legend']]) { r = await api('/api/my/gamepass/buy', { data: { tier } }, hM);
ok(r.status === 400 && r.j.error === 'The ' + name + ' pass is not open yet.', 'member, sovTiers off: ' + name + ' buy refused', JSON.stringify(r.j)); }
g = (await api('/api/my/gamepass', null, hM)).j; ok(!g.active && !g.waiting && g.passes.length === 1, 'the refused buys left the member with no pass and no waiting order', JSON.stringify({ a: g.active, w: g.waiting }));
browser = await chromium.launch();
{ const { page, errs, ctx } = await pageFor(hM); await page.goto(B + '/my#passes'); await page.waitForSelector('#gpCard:not([hidden]) #gpBuy', { timeout: 15000 });
const txt = await page.textContent('#gpCard'); ok(!/Explorer|Champion/.test(txt) && errs.length === 0, 'member page: the weekly card as before, no Explorer/Champion text, no page errors', errs.join(' | '));
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)
g = (await api('/api/my/gamepass', null, hA)).j;
ok(g.tierPreview === true && g.passes.map(x => x.tier).join() === 'weekly,explorer,champion', 'admin, sovTiers off: preview with all three tiers', JSON.stringify(g.passes.map(x => [x.tier, x.price, x.open])));
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);
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());
await page.locator('#gpCard').screenshot({ path: path.join(SHOTS, '2-admin-preview-three-tiers.png') });
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') });
await page.click('#dlgOk');
@@ -102,9 +109,7 @@ try {
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() }));
ok(/gamepass bought with credits explorer qa-admin@example.com 2000/.test(srvLog), 'paid through the real ads.gamePurchase(purchasedOnly) path, 2000 credits', '');
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && r.j.available === 500 && /\$20 package/.test(r.j.message), 'a second Explorer: only 500 purchased credits left -> waiting order, "$20 package"', JSON.stringify({ needPay: r.j.needPay, available: r.j.available, payUrl: r.j.payUrl }));
ok(/gamepass bought with credits explorer qa-admin@example.com 1999/.test(srvLog), 'paid through the real ads.gamePurchase(purchasedOnly) path, 1999 credits', '');
// 3. the Shards of Valor hand-off token and the partner player answer carry tier explorer
const ho = await api('/api/my/shardsofvalor', null, hA);
@@ -119,15 +124,41 @@ try {
const gr = await grant({ memberId: 0, email: ADMIN_EMAIL, game: 'shardsofvalor', kind: 'daily', pol: 0.2, ref: 'qa:1' });
ok(gr.pass === true && gr.allowed === 0.2, 'polgrant: pass true (a boolean) for the Explorer holder', JSON.stringify(gr));
// 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);
ok(r.status === 200 && r.j.ok && r.j.tier === 'sovereign' && r.j.days === 30 && Math.abs(r.j.until - (Date.now() + 30 * 86400000)) < 120000, 'admin buys Sovereign (sovTiers off, testing): 30 days', JSON.stringify(r.j));
ok(/gamepass bought with credits sovereign qa-admin@example.com 9999/.test(srvLog), 'Sovereign paid through the real ads.gamePurchase(purchasedOnly) path, 9999 credits', '');
r = await api('/api/my/gamepass/buy', { data: { tier: 'explorer' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'explorer' && r.j.available === 500 && /\$20 package/.test(r.j.message), 'a second Explorer: only 500 purchased credits left -> waiting order, "$20 package"', JSON.stringify({ needPay: r.j.needPay, available: r.j.available, payUrl: r.j.payUrl }));
r = await api('/api/my/gamepass/buy', { data: { tier: 'legend' } }, hA);
ok(r.status === 200 && r.j.needPay === true && r.j.tier === 'legend' && r.j.available === 500 && r.j.price === 24999 && r.j.payUrl === '/my?from=gamepass&tier=legend#buy' && /\$250 package/.test(r.j.message), 'Legend with 500 credits: waiting order, "$250 package", 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;
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));
g = (await api('/api/my/gamepass', null, hA)).j;
const lg = g.passes.find(x => x.tier === 'legend'), sv = g.passes.find(x => x.tier === 'sovereign');
ok(g.active && g.tier === 'legend' && g.until === lg.until && lg.active && sv.active && lg.days === 365, 'GET /api/my/gamepass: tier legend (highest), Sovereign and Explorer still running underneath', JSON.stringify({ tier: g.tier, l: lg.until, s: sv.until }));
const ho2 = await api('/api/my/shardsofvalor', null, hA); const t2 = new URL(ho2.headers.get('location') || 'http://x/').searchParams.get('t'); const c2 = t2 ? decode(t2) : null;
ok(c2 && c2.gamePass && c2.gamePass.active === true && c2.gamePass.tier === 'legend' && c2.gamePass.until === lg.until, 'hand-off token: gamePass { active, until, tier: legend }', JSON.stringify(c2 && c2.gamePass));
const pl2 = await playerOf(ADMIN_EMAIL);
ok(pl2.status === 200 && pl2.j.pass.tier === 'legend' && pl2.j.pass.tiers.legend === lg.until && pl2.j.pass.tiers.sovereign === sv.until && pl2.j.pass.tiers.explorer === ex.until + 30 * 86400000 && pl2.j.pass.tiers.champion === null && pl2.j.caps.daily === 1.5 && pl2.j.caps.total === 5, 'GET /api/partner/player: tier legend, tiers carry sovereign + legend, weekly pass caps 1.50 / 5', JSON.stringify(pl2.j.pass));
const gr2 = await grant({ memberId: 0, email: ADMIN_EMAIL, game: 'shardsofvalor', kind: 'daily', pol: 5, ref: 'qa:2' });
ok(gr2.pass === true && gr2.enforced === false && gr2.allowed === 5, 'polgrant: pass true (a boolean) for the Legend holder (caps not enforced on this copy: no capsStartDate; the cap values are the player answer above)', JSON.stringify(gr2));
// 4. Admin > Game Pass: the tier table
const st = (await api('/api/admin/gamepass/stats', null, adminH)).j;
ok(st.tiers && st.tiers.explorer.active === 1 && st.tiers.explorer.soldTotal === 1 && st.tiers.explorer.usdTotal === 20 && st.tiers.explorer.waitingOrders === 1 && st.tierSales === false, 'admin stats: Explorer 1 active, 1 sold ($20), 1 waiting; sale switch off', JSON.stringify(st.tiers.explorer));
ok(st.tiers && st.tiers.explorer.active === 0 && st.tiers.explorer.soldTotal === 2 && st.tiers.explorer.usdTotal === 39.98 && st.tiers.explorer.waitingOrders === 0 && st.tierSales === false, 'admin stats: Explorer 2 sold ($39.98: credits + the $100 package order), not counted active (the account is at Legend); sale switch off', JSON.stringify(st.tiers.explorer));
ok(st.tiers.sovereign && st.tiers.sovereign.active === 0 && st.tiers.sovereign.soldTotal === 1 && st.tiers.sovereign.usdTotal === 99.99 && st.tiers.legend.active === 1 && st.tiers.legend.soldTotal === 1 && st.tiers.legend.usdTotal === 249.99 && st.tiers.legend.waitingOrders === 0 && st.settings.tiers.legend.days === 365 && st.settings.tiers.sovereign.sale === false, 'admin stats: Sovereign 1 sold ($99.99), Legend 1 active + 1 sold ($249.99), not on sale', JSON.stringify({ s: st.tiers.sovereign, l: st.tiers.legend }));
{ 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.waitForFunction(() => /Explorer/.test((document.getElementById('gpTiers') || {}).textContent || ''), null, { timeout: 10000 }).catch(() => {}); }
const txt = await page.textContent('#gpTiers').catch(() => '');
ok(/Explorer/.test(txt) && /Champion/.test(txt), 'Admin > Game Pass renders the per-tier table', errs.join(' | ') || (nav ? '' : 'admin nav not found (sign-in flow)'));
ok(/Explorer/.test(txt) && /Champion/.test(txt) && /Sovereign/.test(txt) && /Legend/.test(txt) && /365 d/.test(txt), 'Admin > Game Pass renders the per-tier table (all five, Legend 365 d)', errs.join(' | ') || (nav ? '' : 'admin nav not found (sign-in flow)'));
await sleep(800); await page.locator('#gpTiers').evaluate(e => e.closest('.card').scrollIntoView()); await sleep(400); await page.locator('#gpTiers').evaluate(e => e.closest('.card').id = 'gpTiersCard'); await page.locator('#gpTiersCard').screenshot({ path: path.join(SHOTS, '5-admin-gamepass-tiers.png') }); await ctx.close(); }
} catch (e) {
console.error('FAIL harness error', e && e.stack || e); fails++;
+101 -6
View File
@@ -4,6 +4,8 @@
// extend from max(now, until), side-by-side expiry, highest active tier wins, the sovTiers switch (off refuses, admin may buy),
// waiting orders per tier fulfilled by a big-enough package (each tx once, highest price first), the same caps for every tier
// (no extra POL), comp and revoke, admin stats per tier (each account once at its top tier, Central week/month). Exit 1 on failure.
// 2026-10-22: section 10 adds Sovereign (9999 / 30 days) and the yearly Legend (24999 / 365 days): rank, off-switch refusal,
// buy, short -> waiting order ($100 / $250 package), extend from max(now, until), kill switches, comp/revoke, flag payload, stats.
'use strict';
const fs = require('fs'); const os = require('os'); const path = require('path');
const gp = require('../gamepass');
@@ -40,7 +42,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
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 });
ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion' && v.tierPreview === true && v.passes[1].open === true && v.passes[1].price === 2000 && v.passes[2].price === 4000 && v.passes[1].days === 30, 'sovTiers off: the admin sees all three (preview), prices 2000 / 4000, 30 days', JSON.stringify(v.passes));
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 gp.buy('admin@x.com', paid, T0, 'explorer', { admin: 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 gp.buy('a@x.com', paid, T0); // tier missing = weekly
@@ -54,15 +56,15 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
// 3. on: each tier extends only itself; buying again extends from max(now, until)
charged = null; r = await gp.buy('b@x.com', async (price, label) => { charged = { price, label }; return { ok: true }; }, T0, 'explorer');
ok(r.ok && r.until === T0 + 30 * DAY && charged.price === 2000 && charged.label === 'Explorer pass (30 days)', 'sovTiers on: Explorer charges 2000 credits, 30 days', JSON.stringify(charged));
ok(r.ok && r.until === T0 + 30 * DAY && charged.price === 1999 && charged.label === 'Explorer pass (30 days)', 'sovTiers on: Explorer charges 1999 credits, 30 days', JSON.stringify(charged));
let rec = passes.get('b@x.com');
ok(rec.tiers.explorer.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.champion && rec.until === 0 && rec.bought[0].tier === 'explorer' && rec.bought[0].usd === 20, 'only the Explorer tier moved; legacy until (weekly) stays 0; bought row has tier + $20', JSON.stringify(rec));
ok(rec.tiers.explorer.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.champion && rec.until === 0 && rec.bought[0].tier === 'explorer' && rec.bought[0].usd === 19.99, 'only the Explorer tier moved; legacy until (weekly) stays 0; bought row has tier + $19.99', JSON.stringify(rec));
r = await gp.buy('b@x.com', paid, T0 + 10 * DAY, 'explorer');
ok(r.until === T0 + 60 * DAY, 'Explorer again while active: extends from its until (+30 days, nothing lost)', new Date(r.until).toISOString());
r = await gp.buy('c@x.com', paid, T0, 'champion'); ok(r.ok && r.until === T0 + 30 * DAY, 'Champion: 30 days', '');
r = await gp.buy('c@x.com', paid, T0 + 45 * DAY, 'champion');
ok(r.until === T0 + 75 * DAY, 'Champion again after it ended: extends from now', new Date(r.until).toISOString());
charged = null; await gp.buy('c2@x.com', async (price) => { charged = price; return { ok: true }; }, T0, 'champion'); ok(charged === 4000, 'Champion charges 4000 credits', String(charged));
charged = null; await gp.buy('c2@x.com', async (price) => { charged = price; return { ok: true }; }, T0, 'champion'); ok(charged === 3999, 'Champion charges 3999 credits', String(charged));
// 4. side by side: Champion over Explorer, then Explorer shows through; weekly underneath
await gp.buy('d@x.com', paid, T0, 'weekly'); // weekly to T0+7
@@ -133,7 +135,7 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
await gp.buy('s5@x.com', short, NOW, 'champion');
const st = gp.adminStats(NOW); const S = st.tiers;
ok(S.weekly.active === 1 && S.explorer.active === 2 && S.champion.active === 1, 'active counts each account once at its top tier (s1 = explorer, not weekly)', JSON.stringify({ w: S.weekly.active, e: S.explorer.active, c: S.champion.active }));
ok(S.weekly.soldWeek === 2 && S.explorer.soldWeek === 0 && S.explorer.soldMonth === 1 && S.champion.soldWeek === 1 && S.champion.soldMonth === 1 && S.champion.soldTotal === 2 && S.champion.usdTotal === 80, 'Central week (from Mon 00:00) and month (from the 1st 00:00) boundaries', JSON.stringify({ w: [S.weekly.soldWeek, S.weekly.soldMonth], e: [S.explorer.soldWeek, S.explorer.soldMonth], c: [S.champion.soldWeek, S.champion.soldMonth, S.champion.soldTotal, S.champion.usdTotal] }));
ok(S.weekly.soldWeek === 2 && S.explorer.soldWeek === 0 && S.explorer.soldMonth === 1 && S.champion.soldWeek === 1 && S.champion.soldMonth === 1 && S.champion.soldTotal === 2 && S.champion.usdTotal === 79.98, 'Central week (from Mon 00:00) and month (from the 1st 00:00) boundaries', JSON.stringify({ w: [S.weekly.soldWeek, S.weekly.soldMonth], e: [S.explorer.soldWeek, S.explorer.soldMonth], c: [S.champion.soldWeek, S.champion.soldMonth, S.champion.soldTotal, S.champion.usdTotal] }));
ok(S.champion.renewals30d === 1 && S.weekly.renewals30d === 0, 'renewals30d: a second Champion purchase by a Champion holder', String(S.champion.renewals30d));
ok(S.weekly.expiring7d === 2 && S.explorer.comped === 1 && S.champion.waitingOrders === 1, 'expiring7d (weekly passes ending in 7 Central days), comped, waiting orders per tier', JSON.stringify({ exp: S.weekly.expiring7d, comped: S.explorer.comped, wait: S.champion.waitingOrders }));
ok(st.passes.active === 4 && st.passes.soldTotal === 5 && st.passes.comped === 1 && st.passes.waitingOrders === 1, 'the existing all-tier passes block still adds up', JSON.stringify(st.passes));
@@ -143,7 +145,100 @@ const short = async () => ({ error: 'short', available: 0, need: 1 });
ok(rows.sales === 2 && rows.salesUsd === 10, 'passTournamentTierSales off: only the 2 weekly sales ($10) feed the pool', JSON.stringify({ sales: rows.sales, usd: rows.salesUsd }));
SC.passTournamentTierSales = '1';
const rows2 = await gp.runTournament(Date.parse('2026-11-03T18:00:00Z'), { force: true });
ok(rows2.sales === 3 && rows2.salesUsd === 50, 'passTournamentTierSales on: the Champion renewal ($40) is added', JSON.stringify({ sales: rows2.sales, usd: rows2.salesUsd }));
ok(rows2.sales === 3 && rows2.salesUsd === 49.99, 'passTournamentTierSales on: the Champion renewal ($39.99) is added', JSON.stringify({ sales: rows2.sales, usd: rows2.salesUsd }));
// 10. Sovereign ($99.99 / 30 days) and Legend ($249.99 / 365 days), 2026-10-22 (Dallas's structure)
for (const k of [...passes.keys()]) passes.delete(k); for (const k of [...orders.keys()]) orders.delete(k);
delete SC.passTournamentTierSales; SC.sovTiers = '0';
ok(gp.TIERS.join() === 'weekly,explorer,champion,sovereign,legend' && gp.TIER_NAMES.sovereign === 'Sovereign' && gp.TIER_NAMES.legend === 'Legend', 'rank: weekly < explorer < champion < sovereign < legend; names from the one table', gp.TIERS.join());
const C0 = gp.cfg().tiers;
ok(C0.weekly.price === 500 && C0.weekly.days === 7 && C0.explorer.price === 1999 && C0.champion.price === 3999 && C0.sovereign.price === 9999 && C0.sovereign.days === 30 && C0.legend.price === 24999 && C0.legend.days === 365 && !C0.sovereign.sale && !C0.legend.sale && C0.weekly.sale, 'defaults: weekly 500/7 (unchanged), Sovereign 9999/30, Legend 24999/365; sovTiers off = not on sale, weekly on sale', JSON.stringify(C0));
// off switch: members refused, nothing written, nothing charged; the weekly pass still sells
charged = null; const spy = async (price, label) => { charged = { price, label }; return { ok: true }; };
r = await gp.buy('m@x.com', spy, T0, 'sovereign'); ok(r.error === 'The Sovereign pass is not open yet.' && !charged, 'sovTiers off: Sovereign refused for a member, nothing charged', JSON.stringify(r));
r = await gp.buy('m@x.com', spy, T0, 'legend'); ok(r.error === 'The Legend pass is not open yet.' && !charged, 'sovTiers off: Legend refused for a member, nothing charged', JSON.stringify(r));
r = await gp.buy('m@x.com', short, T0, 'legend'); ok(r.error && !orders.size, 'sovTiers off: a short member gets no waiting Legend order either', JSON.stringify(r));
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 gp.buy('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 gp.buy('adm@x.com', spy, T0, 'legend', { admin: 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
charged = null; r = await gp.buy('sv@x.com', spy, T0, 'sovereign');
ok(r.ok && r.tier === 'sovereign' && r.days === 30 && r.until === T0 + 30 * DAY && charged.price === 9999 && charged.label === 'Sovereign pass (30 days)', 'sovTiers on: Sovereign charges 9999 credits, 30 days', JSON.stringify(charged));
rec = passes.get('sv@x.com');
ok(rec.tiers.sovereign.until === T0 + 30 * DAY && !rec.tiers.weekly && !rec.tiers.legend && rec.until === 0 && rec.bought[0].tier === 'sovereign' && rec.bought[0].usd === 99.99 && rec.bought[0].credits === 9999, 'only the Sovereign tier moved; bought row has tier, $99.99, 9999 credits', JSON.stringify(rec));
charged = null; r = await gp.buy('lg@x.com', spy, T0, 'legend');
ok(r.ok && r.until === T0 + 365 * DAY && charged.price === 24999 && passes.get('lg@x.com').bought[0].usd === 249.99, 'sovTiers on: Legend charges 24999 credits, a YEAR (365 days), $249.99 row', JSON.stringify(charged));
// extend: from max(now, until)
r = await gp.buy('lg@x.com', paid, T0 + 100 * DAY, 'legend'); ok(r.until === T0 + 730 * DAY, 'Legend again while active: +365 days from its end (nothing lost)', new Date(r.until).toISOString());
r = await gp.buy('sv@x.com', paid, T0 + 10 * DAY, 'sovereign'); ok(r.until === T0 + 60 * DAY, 'Sovereign again while active: +30 days from its end', new Date(r.until).toISOString());
r = await gp.buy('sv@x.com', paid, T0 + 90 * DAY, 'sovereign'); ok(r.until === T0 + 120 * DAY, 'Sovereign again after it ended: +30 days from now', new Date(r.until).toISOString());
r = await gp.buy('lg2@x.com', paid, T0, 'legend'); r = await gp.buy('lg2@x.com', paid, T0 + 400 * DAY, 'legend'); ok(r.until === T0 + 765 * DAY, 'Legend again after it ended: +365 days from now', new Date(r.until).toISOString());
// ordering: all five side by side
await gp.buy('all@x.com', paid, T0, 'weekly'); await gp.buy('all@x.com', paid, T0, 'explorer'); await gp.buy('all@x.com', paid, T0, 'champion');
await gp.buy('all@x.com', paid, T0, 'sovereign'); await gp.buy('all@x.com', paid, T0 - 360 * DAY, 'legend'); // legend to T0+5
f = gp.flag('all@x.com', T0 + DAY);
ok(f.active && f.tier === 'legend' && f.until === T0 + 5 * DAY && f.tiers.sovereign === T0 + 30 * DAY && f.tiers.legend === T0 + 5 * DAY && f.tiers.champion === T0 + 30 * DAY && f.tiers.weekly === T0 + 7 * DAY && Object.keys(f.tiers).join() === 'weekly,explorer,champion,sovereign,legend', 'all five on: tier legend, until = Legend end, every tier side by side in the payload', JSON.stringify(f));
f = gp.flag('all@x.com', T0 + 6 * DAY); ok(f.tier === 'sovereign' && f.until === T0 + 30 * DAY && f.tiers.legend === null, 'Legend ended: Sovereign shows through (above Champion and Explorer, same end)', JSON.stringify(f));
await gp.buy('ce@x.com', paid, T0, 'champion'); await gp.buy('ce@x.com', paid, T0, 'sovereign'); await gp.buy('ce@x.com', paid, T0, 'explorer');
ok(gp.flag('ce@x.com', T0 + 1).tier === 'sovereign', 'Sovereign outranks Champion and Explorer whatever the buy order', gp.flag('ce@x.com', T0 + 1).tier);
// the same caps (no extra POL) and pass: true
const at2 = Date.parse('2026-10-22T17:00:00Z');
ok([gp.capsFor('sv@x.com', at2), gp.capsFor('lg@x.com', at2)].every(c => c.pass === true && c.daily === 1.5 && c.total === 5), 'capsFor: Sovereign and Legend holders get exactly the weekly pass caps 1.50 / 5', '');
const gs = gp.grant({ email: 'lg@x.com', game: 'shardsofvalor', kind: 'daily', pol: 3, ref: 'cap:lg', now: at2 });
ok(gs.allowed === 1.5 && gs.pass === true, 'polgrant: a Legend holder is capped at 1.50 on daily play, pass: true (a boolean)', JSON.stringify(gs));
// waiting orders: a $50 package does not cover Sovereign, $100 does; $100 does not cover Legend, $250 does
r = await gp.buy('wo@x.com', short, T0, 'sovereign');
ok(r.needPay && r.tier === 'sovereign' && r.payUrl === '/my?from=gamepass&tier=sovereign#buy' && r.package === 100 && /\$100 package/.test(r.message) && r.price === 9999, 'Sovereign short: waiting order, payUrl with tier, "$100 package"', r.message);
const ordS = r.order;
r = await gp.buy('wo@x.com', short, T0, 'legend'); const ordL = r.order;
ok(r.needPay && r.order !== ordS && r.package === 250 && /\$250 package/.test(r.message) && r.payUrl === '/my?from=gamepass&tier=legend#buy', 'Legend short: its own waiting order, "$250 package"', r.message);
r = await gp.buy('wo@x.com', short, T0, 'legend'); ok(r.order === ordL, 'Legend again: reuses its waiting order', '');
ev = await gp.onEvent({ type: 'Purchase', priceCents: 5000, tx: '0xd1', ts: T0, devEmail: 'wo@x.com' }); ok(ev === null, 'a $50 package fulfils neither Sovereign nor Legend', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd2', ts: T0, devEmail: 'wo@x.com' });
ok(ev && ev.tier === 'sovereign' && ev.order === ordS && ev.until === T0 + 30 * DAY, 'a $100 package fulfils the Sovereign order (not Legend)', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd2', ts: T0, devEmail: 'wo@x.com' }); ok(ev === null, 'the same tx again counts once', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 25000, tx: '0xd3', ts: T0, devEmail: 'wo@x.com' });
ok(ev && ev.tier === 'legend' && ev.order === ordL && ev.until === T0 + 365 * DAY, 'a $250 package fulfils the Legend order: a year', JSON.stringify(ev));
await gp.buy('wo2@x.com', short, T0, 'champion'); await gp.buy('wo2@x.com', short, T0, 'sovereign'); await gp.buy('wo2@x.com', short, T0, 'legend');
ev = await gp.onEvent({ type: 'Purchase', priceCents: 50000, tx: '0xd4', ts: T0, devEmail: 'wo2@x.com' }); ok(ev && ev.tier === 'legend', 'three orders waiting, a $500 package: Legend (the highest-priced it covers) first', JSON.stringify(ev));
ev = await gp.onEvent({ type: 'Purchase', priceCents: 10000, tx: '0xd5', ts: T0, devEmail: 'wo2@x.com' }); ok(ev && ev.tier === 'sovereign', 'then a $100 package: Sovereign', JSON.stringify(ev));
// kill switches: one tier stops alone, the rest keep selling
SC.gamePassLegendEnabled = '0';
r = await gp.buy('ks@x.com', paid, T0, 'legend'); const r2 = await gp.buy('ks@x.com', paid, T0, 'sovereign');
ok(r.error === 'The Legend pass is not open yet.' && r2.ok, 'gamePassLegendEnabled 0: Legend refused, Sovereign still sells', JSON.stringify(r));
v = gp.view('ks2@x.com', T0); ok(v.passes.map(x => x.tier).join() === 'weekly,explorer,champion,sovereign', 'a stopped tier drops off the member card', v.passes.map(x => x.tier).join());
v = gp.view('lg@x.com', T0); const lrow = v.passes.find(x => x.tier === 'legend');
ok(lrow && lrow.active && !lrow.open, 'a Legend holder still sees their pass (not on sale) after the switch stops it', JSON.stringify(lrow));
delete SC.gamePassLegendEnabled; SC.gamePassSovereignEnabled = '0';
r = await gp.buy('ks@x.com', paid, T0, 'sovereign'); ok(r.error === 'The Sovereign pass is not open yet.', 'gamePassSovereignEnabled 0: Sovereign refused', JSON.stringify(r));
delete SC.gamePassSovereignEnabled;
SC.gamePassLegendPriceCredits = '20000'; SC.gamePassLegendDays = '180';
charged = null; r = await gp.buy('pr@x.com', spy, T0, 'legend'); ok(charged.price === 20000 && r.until === T0 + 180 * DAY, 'gamePassLegendPriceCredits / gamePassLegendDays settings override the defaults', JSON.stringify(charged));
delete SC.gamePassLegendPriceCredits; delete SC.gamePassLegendDays;
// comp and revoke
cp = gp.comp('cv@x.com', 'qa', 'legend', T0); f = gp.flag('cv@x.com', T0 + 1);
ok(cp.tier === 'legend' && cp.days === 365 && cp.until === T0 + 365 * DAY && f.tier === 'legend' && passes.get('cv@x.com').bought[0].via === 'admin' && passes.get('cv@x.com').bought[0].usd === 0, 'comp Legend: a year, an admin row worth $0', JSON.stringify(cp));
gp.comp('cv@x.com', 'qa', 'sovereign', T0);
rv = gp.revoke('cv@x.com', 'legend', 'refund qa', T0 + DAY); f = gp.flag('cv@x.com', T0 + DAY + 1);
ok(rv.ok && rv.tier === 'legend' && f.tier === 'sovereign' && f.tiers.legend === null, 'revoke Legend: ends now, Sovereign shows through', JSON.stringify(f));
rv = gp.revoke('cv@x.com', 'sovereign', 'refund qa', T0 + DAY); ok(rv.ok && gp.flag('cv@x.com', T0 + DAY + 1).active === false, 'revoke Sovereign: no pass left', JSON.stringify(rv));
rv = gp.revoke('cv@x.com', 'legend', 'again', T0 + 2 * DAY); ok(rv.error === 'No active Legend pass on this account.', 'revoking an inactive Legend is refused', rv.error);
// admin stats: per tier, each account once at its top tier; comps are not sales
const st2 = gp.adminStats(T0 + DAY); const S2 = st2.tiers;
ok(Object.keys(S2).join() === 'weekly,explorer,champion,sovereign,legend' && S2.sovereign.name === 'Sovereign' && S2.legend.name === 'Legend', 'admin stats carry all five tiers by name', Object.keys(S2).join());
ok(S2.legend.active >= 3 && S2.legend.comped === 1 && S2.sovereign.comped === 1 && S2.legend.soldTotal >= 4 && S2.sovereign.soldTotal >= 4, 'admin stats: Legend/Sovereign active, sold and comped counted', JSON.stringify({ l: S2.legend, s: S2.sovereign }));
ok(st2.settings.tiers.legend.days === 365 && st2.settings.tiers.sovereign.price === 9999, 'admin settings block shows Legend 365 days, Sovereign 9999', '');
// tournament: Legend/Sovereign sales stay out of the pool unless passTournamentTierSales
for (const k of [...passes.keys()]) passes.delete(k);
const wkT = Date.parse('2026-11-10T18:00:00Z');
await gp.buy('t1@x.com', paid, wkT, 'weekly'); await gp.buy('t2@x.com', paid, wkT, 'legend'); await gp.buy('t3@x.com', paid, wkT, 'sovereign');
let tr = await gp.runTournament(wkT, { force: true }); ok(tr.sales === 1 && tr.salesUsd === 5, 'passTournamentTierSales default off: Sovereign/Legend sales do not feed the pool', JSON.stringify({ s: tr.sales, u: tr.salesUsd }));
SC.passTournamentTierSales = '1';
tr = await gp.runTournament(wkT, { force: true }); ok(tr.sales === 3 && tr.salesUsd === 354.98, 'passTournamentTierSales on: Legend ($249.99) and Sovereign ($99.99) are added', JSON.stringify({ s: tr.sales, u: tr.salesUsd }));
delete SC.passTournamentTierSales;
try { fs.rmSync(dataDir, { recursive: true, force: true }); } catch (e) {}
console.log(fails ? fails + ' FAILURE(S)' : 'ALL PASS');
process.exit(fails ? 1 : 0);
+7 -4
View File
@@ -543,7 +543,7 @@ async function boot() {
messages.init({ dataDir: DATA_DIR });
reports.init({ dataDir: DATA_DIR });
drip.init({ dataDir: DATA_DIR, mailer, accounts, chain, site: 'https://instantadpay.com' });
chatbot.init({ dataDir: DATA_DIR, chain });
chatbot.init({ dataDir: DATA_DIR, chain, passTiers: () => { const c = gamepass.cfg(); return { on: c.enabled && c.tierSales, rows: gamepass.TIER_DEFS.filter(d => d.key !== 'weekly').map(d => ({ name: d.name, perks: d.perks, price: c.tiers[d.key].price, usd: c.tiers[d.key].price / 100, days: c.tiers[d.key].days, sale: c.tiers[d.key].sale })) }; } }); // pass tiers fact follows sovTiers (2026-10-22)
setTimeout(() => ads.dailySweep().catch(e => console.error('sweep', e.message)), 60 * 1000);
setInterval(() => ads.dailySweep().catch(e => console.error('sweep', e.message)), 60 * 60 * 1000);
setInterval(() => ads.scheduleSweep().catch(e => console.error('schedule sweep', e.message)), 5 * 60 * 1000); // scheduled starts/ends
@@ -714,7 +714,7 @@ async function polUsdLive() {
const v = (pk.priceCents / 100) / (Number(BigInt(pk.costWei)) / 1e18); if (v > 0) { polUsdCache.v = v; polUsdCache.at = Date.now(); } return v;
}
// the Game Pass flag rides in every sign-in hand-off token (3a: games get it at sign-in and on every polgrant answer)
// gamePass: { active, until, tier } (tier = the highest active pass: weekly | explorer | champion | null; a game treats a missing tier as weekly)
// gamePass: { active, until, tier } (tier = the highest active pass: weekly | explorer | champion | sovereign | legend | null; a game treats a missing tier as weekly)
const gpClaim = c => { if (!(c && c.email && (!c.kind || c.kind === 'sso'))) return {}; const f = gamepass.flag(c.email); return { gamePass: { active: f.active, until: f.until, tier: f.tier } }; };
function siteConfig() {
let saved = {};
@@ -750,7 +750,10 @@ function siteConfig() {
// in Shards of Valor, never power, never more POL (same caps as the weekly pass). sovTiers = the sale switch for both (off: only ADMIN_EMAIL
// sees and can buy them, for testing; holders keep their pass). gamePass<Tier>Enabled '0' stops one tier alone. passTournamentTierSales '1'
// would add their sales to the Pass Tournament pool (off = the pool exactly as before).
sovTiers: '0', gamePassExplorerEnabled: '1', gamePassExplorerPriceCredits: 2000, gamePassExplorerDays: 30, gamePassChampionEnabled: '1', gamePassChampionPriceCredits: 4000, gamePassChampionDays: 30, passTournamentTierSales: '0',
// 2026-10-22 (Dallas's structure, Marty approved): Explorer $19.99 / Champion $39.99 for 30 days, plus Sovereign $99.99 for 30 days and
// Legend $249.99 for 365 days (the yearly pass), all behind sovTiers. Names, perks and the rank live in gamepass.js TIER_DEFS.
sovTiers: '0', gamePassExplorerEnabled: '1', gamePassExplorerPriceCredits: 1999, gamePassExplorerDays: 30, gamePassChampionEnabled: '1', gamePassChampionPriceCredits: 3999, gamePassChampionDays: 30,
gamePassSovereignEnabled: '1', gamePassSovereignPriceCredits: 9999, gamePassSovereignDays: 30, gamePassLegendEnabled: '1', gamePassLegendPriceCredits: 24999, gamePassLegendDays: 365, passTournamentTierSales: '0',
supportTelegramChat: '1289244227', // help desk pings: Marty's PRIVATE chat only (a positive user id; group/channel ids are refused). Sent with telegramBotToken, Hermes bot as fallback
supportTemplates: '', // help desk saved replies, JSON [{name, body}] (Admin > Support > Saved replies); empty = the built-in set
telegramGamesChatId: '', telegramGamesTopicId: '661565', // Game Achievements topic for the weekly Pass Tournament post (chat blank = the shared echo chat)
@@ -3965,7 +3968,7 @@ const server = http.createServer(async (req, res) => {
const b = await readBody(req); const { ids } = await myMemberIds(s);
// purchased-grade credits only, from a position's package balance (the PolyWarriors mint rule); devPaid = local tests only
const charge = (!IS_PROD && b.devPaid) ? async () => ({ ok: true, campaignId: 0, dev: true }) : (price, label) => ads.gamePurchase(s.email, ids, price, label, 'https://instantadpay.com/my#games', { purchasedOnly: true });
// tier: weekly (missing) | explorer | champion; Explorer/Champion are refused unless sovTiers is on, except for the ADMIN_EMAIL account (testing)
// 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 = await gamepass.buy(s.email, charge, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
return json(res, r.error ? 400 : 200, r);
}