// Admin: checks (cost, timings, publish to "Network, checked"), test purchases with the sponsor line that would be paid, // voucher codes (create, disable, redemptions), and an admin-run check for our own contracts. The token stays in this browser. (function () { 'use strict'; var $ = WWI.$, esc = WWI.esc, tok = ''; try { tok = sessionStorage.getItem('wwi.admin') || ''; } catch (e) {} function api(path, body) { return fetch(path, { method: body ? 'POST' : 'GET', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: body ? JSON.stringify(body) : undefined }).then(function (r) { return r.json(); }); } var ct = function (t) { return t ? new Date(Number(t)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : ''; }; function load() { api('/api/admin/overview').then(function (j) { if (j.error) { $('out').innerHTML = '
' + esc(j.error) + '
'; return; } $('tok').classList.add('hide'); var h = '
Totals' + j.cost.n + ' checks, OpenRouter cost $' + Number(j.cost.usd || 0).toFixed(4) + '. Hub sign-in ' + (j.sso ? 'on' : 'off') + '. Ad zones: ' + (Object.keys(j.zones || {}).length ? esc(JSON.stringify(j.zones)) : 'none set (WWI_ZONES)') + '.
'; h += '
Run a check (admin, no limit)
'; h += '
ChecksTick Public to show a check on "Network, checked"; the label comes from this box:
' + j.checks.map(function (c) { var tm = c.timings_json ? JSON.parse(c.timings_json) : null; return '' + ''; }).join('') + '
WhenKindWhatStatusModelCostTimePublic
' + ct(c.created) + '' + esc(c.kind) + '' + esc(c.website || '') + ' ' + esc(WWI.short(c.address) || '') + ' ' + esc(c.chain || '') + '' + (c.error ? '
' + esc(c.error.slice(0, 160)) + '' : '') + '
' + esc(c.status) + (c.status !== 'done' ? ' (' + esc(c.step || '') + ')' : '') + '' + esc(c.model || '') + '$' + Number(c.cost_usd || 0).toFixed(4) + '' + (tm ? Math.round(tm.total_s) + ' s' : '') + '
'; h += '
Join and sign-in links (no email is sent while MAIL_URL is unset)
' + (j.joins || []).map(function (x) { return ''; }).join('') + '
WhenEmailRefOpt-inBack toStatusHub
' + ct(x.created) + '' + esc(x.email) + '' + esc(x.ref || '') + '' + (x.optin ? 'yes' : 'no') + '' + esc(x.to_path || '') + '' + esc(x.status) + (x.mailed ? ', mailed' : '') + '' + esc(x.hub_result || '') + '
'; h += '
Test purchases and the sponsor line (nothing paid in staging)
' + j.purchases.map(function (p) { var s = p.split || {}; var l = p.line || {}; return ''; }).join('') + '
WhenBuyerItemViaRefLine sourceWould payCompany
' + ct(p.at) + '' + esc(p.buyer_username ? '@' + p.buyer_username : p.buyer || 'visitor') + '' + esc(p.item) + ' $' + Number(p.usd).toFixed(2) + '' + esc(p.via) + '' + esc(p.ref || '') + '' + esc(l.source || '') + (l.ok === false ? ' (hub partial)' : '') + '
' + (l.line || []).map(function (x) { return (x.username ? '@' + esc(x.username) : esc(WWI.short(x.wallet) || '?')) + (x.qualified ? ' (bought)' : ' (passed over)'); }).join(' > ') + '
' + (s.levels || []).map(function (x) { return 'L' + x.level + ' ' + x.pct + '% $' + Number(x.usd).toFixed(2) + ' ' + (x.username ? '@' + esc(x.username) : 'company'); }).join('
') + (s.note ? '
' + esc(s.note) + '' : '') + '
$' + Number(s.company || 0).toFixed(2) + '
'; h += '
Vouchers
' + '
' + j.promos.map(function (p) { return ''; }).join('') + '
CodeGivesUsesExpiresNote
' + esc(p.code) + '' + p.amount + ' ' + (p.kind === 'deep' ? 'deep' : 'free') + '' + p.uses + ' / ' + p.max_uses + (p.per_holder_once ? ' (once each)' : '') + '' + (p.expires ? ct(p.expires) : '') + '' + esc(p.note || '') + '
' + 'Redemptions
' + j.redemptions.map(function (r) { return ''; }).join('') + '
WhenCodeHolderGave
' + ct(r.at) + '' + esc(r.code) + '' + esc(String(r.holder).replace(/^t:(.{6}).*/, 'browser $1...')) + '' + r.amount + ' ' + esc(r.kind) + '
'; $('out').innerHTML = h; $('aRun').addEventListener('click', function () { api('/api/admin/check', { address: $('aAddr').value.trim(), website: $('aSite').value.trim(), chain: $('aChain').value, kind: $('aKind').value, label: $('aLabel').value.trim(), public: $('aPub').checked }).then(function (r) { $('aMsg').innerHTML = r.id ? 'Started: ' + r.id + '' : esc(r.error); }); }); $('pMake').addEventListener('click', function () { api('/api/admin/promo', { code: $('pCode').value.trim(), kind: $('pKind').value, amount: $('pAmt').value, maxUses: $('pMax').value, expires: $('pExp').value || null, perHolderOnce: $('pOnce').checked, note: $('pNote').value }).then(function (r) { $('pMsg').textContent = r.ok ? 'Created ' + r.code : r.error; if (r.ok) setTimeout(load, 600); }); }); document.querySelectorAll('[data-dis]').forEach(function (b) { b.addEventListener('click', function () { api('/api/admin/promo/disable', { code: b.getAttribute('data-dis'), enable: b.getAttribute('data-en') === '1' }).then(load); }); }); document.querySelectorAll('[data-pub]').forEach(function (b) { b.addEventListener('change', function () { var label = b.checked ? $('pubLabel').value.trim() : ''; api('/api/admin/publish', { id: b.getAttribute('data-pub'), public: b.checked, label: label }).then(load); }); }); }); } $('save').addEventListener('click', function () { tok = $('token').value.trim(); try { sessionStorage.setItem('wwi.admin', tok); } catch (e) {} load(); }); if (tok) load(); })();