GET /api/admin/member-extra?email= (Marty 2026-11-14, network hub member lookup): read-only, admin Bearer; what the member card leaves out: optedOut (drip unsubscribe), tank {inTank, ready {readyAt, holdUntil}, adoptions summary}. qa/member-extra.mjs in the member run (401 without/with a wrong password, 404 unknown, fields present). qa member: 57 passed 0 failed, member-extra 7/7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// GET /api/admin/member-extra (2026-11-14): the network hub's member lookup reads opt-out, tank and hold state here. Read-only.
|
||||
// Runs against LOCAL (bash qa/run.sh member starts it). Admin = Bearer localtest.
|
||||
const B = process.env.LOCAL || 'http://127.0.0.1:8796';
|
||||
let pass = 0, fail = 0; const ok = (c, m, x) => { if (c) pass++; else { fail++; console.log('[bug] member-extra ' + m + (x ? ' :: ' + x : '')); } };
|
||||
const email = 'mx' + Date.now() + '@example.com'; const ip = '198.51.100.' + (20 + Math.floor(Math.random() * 200));
|
||||
const H = { 'Content-Type': 'application/json', 'X-Forwarded-For': ip, 'User-Agent': 'Mozilla/5.0 MemberExtraQA' };
|
||||
const post = (p, b) => fetch(B + p, { method: 'POST', headers: H, body: JSON.stringify(b) }).then(r => r.json().catch(() => ({})));
|
||||
const get = (q, auth) => fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(q), { headers: auth ? { Authorization: 'Bearer ' + auth } : {} });
|
||||
try {
|
||||
ok((await get(email)).status === 401, 'no admin header is refused');
|
||||
ok((await get(email, 'wrong')).status === 401, 'a wrong admin password is refused');
|
||||
ok((await get(email, 'localtest')).status === 404, 'an unknown email is 404');
|
||||
const st = await post('/api/auth/email/start', { email, fts: Date.now() - 8000, fage: 8000 });
|
||||
if (st.devCode) await post('/api/auth/email/verify', { email, code: st.devCode });
|
||||
const r = await get(email, 'localtest'); const j = await r.json().catch(() => null);
|
||||
ok(r.status === 200 && j, 'a known account answers', r.status);
|
||||
ok(j && j.tank && typeof j.tank.inTank === 'boolean', 'tank.inTank is a boolean', JSON.stringify(j));
|
||||
ok(j && 'optedOut' in j, 'optedOut is present');
|
||||
const w = await fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(email), { method: 'POST', headers: { Authorization: 'Bearer localtest' } });
|
||||
ok(w.status !== 200 || !(await w.text()).includes('optedOut'), 'POST is not a route (read-only)');
|
||||
} catch (e) { fail++; console.log('[bug] member-extra crashed :: ' + e.message); }
|
||||
console.log('member-extra: ' + pass + ' passed, ' + fail + ' failed');
|
||||
process.exit(fail ? 1 : 0);
|
||||
@@ -70,7 +70,7 @@ elif [ "$MODE" = "sso" ]; then
|
||||
node qa/networksso.test.cjs || status=1
|
||||
node qa/networksso.e2e.mjs || status=1
|
||||
elif [ "$MODE" = "member" ]; then
|
||||
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; }; stop_local 8796
|
||||
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; LOCAL=http://127.0.0.1:8796 node qa/member-extra.mjs || status=1; }; stop_local 8796
|
||||
node qa/networksso.test.cjs || status=1 # network sign-in with the other site: tokens, replay, open redirects, loop guard
|
||||
node qa/networksso.e2e.mjs || status=1 # both servers locally, a real browser across them (skips if the other repo is not beside this one)
|
||||
node qa/tank-hold.test.mjs || status=1
|
||||
|
||||
@@ -2287,6 +2287,18 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!a) return json(res, 404, { error: 'No member matches "' + q.slice(0, 60) + '".' });
|
||||
return json(res, 200, await adminMember.view(a.email));
|
||||
}
|
||||
// -- admin: the network hub's member lookup (Marty 2026-11-14, read-only): what the member card leaves out. GET ?email=
|
||||
if (p === '/api/admin/member-extra' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const e = String(u.searchParams.get('email') || '').trim().toLowerCase();
|
||||
const a = e ? await accounts.byEmail(e) : null;
|
||||
if (!a) return json(res, 404, { error: 'no such account' });
|
||||
const r = tank.readyRec(e);
|
||||
return json(res, 200, {
|
||||
optedOut: await drip.isUnsubscribed(e).catch(() => null),
|
||||
tank: { inTank: tank.inTank(a), ready: r ? { readyAt: r.readyAt || null, holdUntil: r.readyAt ? r.readyAt + tank.READY_MS : null } : null, adoptions: await tank.summaryFor(e).catch(() => null) }
|
||||
});
|
||||
}
|
||||
// admin-made tracked links for a member (2026-11-03, Marty: a standalone copy of the games page needs LinkSpin tracking
|
||||
// on every outbound link, built while he was away from his sign-in). POST { email, sourceId? | source?: { name, site },
|
||||
// links: [{ name, url, label }] } -> one rotation per link on that member's account, one destination each, attached to the
|
||||
|
||||
Reference in New Issue
Block a user