Tool tiers for spin links and pages (Marty): Free 3, Starter (any own package) 10, Builder (2 qualifying buyers) 50, Leader (5) unlimited with a 500 fair-use ceiling; existing items above a cap are kept, only new ones wait; Links/Pages headers show N of M (tier); chatbot facts + KNOWLEDGE_DATE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-21 06:58:16 -05:00
parent 33f3b9d337
commit a0daf7925a
6 changed files with 37 additions and 7 deletions
+29 -2
View File
@@ -190,6 +190,31 @@ async function bannerFacts(email) {
try { const ms = await ads.milestonesOf(e); if (ms.includes('level3')) buyers = Math.max(buyers, 5); else if (ms.includes('level2')) buyers = Math.max(buyers, 2); } catch (er) {} // a badge once earned stays earned
const f = { ownBuy, buyers }; bsFacts.set(e, { ts: Date.now(), f }); return f;
}
// Tool tiers for spin links and pages (Marty 2026-10-21: "cap this ... and there needs to be more of an incentive for
// upgrading"): free 3, Starter (any package of your own) 10, Builder (2 qualifying buyers) 50, Leader (5) unlimited with a
// fair-use ceiling. Existing items above a cap are never removed; only new ones wait for the upgrade.
const TOOL_TIERS = { free: { label: 'Free', max: 3, need: '' }, starter: { label: 'Starter', max: 10, need: 'any package of your own' },
builder: { label: 'Builder', max: 50, need: 'level 2 open (2 qualifying buyers)' }, leader: { label: 'Leader', max: 500, unlimited: true, need: 'level 3 open (5 qualifying buyers)' } };
const TOOL_ORDER = ['free', 'starter', 'builder', 'leader'];
const toolCache = new Map();
async function toolTier(email) {
const e = String(email || '').toLowerCase(); const hit = toolCache.get(e); if (hit && Date.now() - hit.ts < 60000) return hit.t;
let key = 'free';
if (ADMIN_EMAIL && e === ADMIN_EMAIL) key = 'leader';
else {
const ids = []; try { const a = await accounts.byEmail(e); if (a && a.memberId) ids.push(a.memberId); for (const pz of await accounts.positions(e)) if (pz.memberId && !ids.includes(pz.memberId)) ids.push(pz.memberId); } catch (er) {}
let paid = false; if (ids.length) { const idset = new Set(ids); for (const ev of chain.recentEvents(200000)) if (ev.type === 'Purchase' && idset.has(ev.buyerId)) { paid = true; break; } }
let buyers = 0; try { buyers = (await bannerFacts(e)).buyers || 0; } catch (er) {}
key = buyers >= 5 ? 'leader' : buyers >= 2 ? 'builder' : paid ? 'starter' : 'free';
}
const t = TOOL_TIERS[key], nk = TOOL_ORDER[TOOL_ORDER.indexOf(key) + 1], n = nk ? TOOL_TIERS[nk] : null;
const out = { key, label: t.label, max: t.max, unlimited: !!t.unlimited, next: n ? { key: nk, label: n.label, max: n.max, unlimited: !!n.unlimited, need: n.need } : null };
toolCache.set(e, { ts: Date.now(), t: out }); return out;
}
function toolCapError(kind, have, t) {
const nx = t.next ? ' ' + t.next.label + ' (' + t.next.need + ') ' + (t.next.unlimited ? 'makes them unlimited.' : 'holds ' + t.next.max + '.') : '';
return 'Your ' + t.label + ' tier holds ' + t.max + ' ' + kind + ' and you have ' + have + '.' + nx;
}
async function myMemberIds(s) {
const main = await auth.refreshMemberId(s);
const ids = main ? [main] : [];
@@ -2244,10 +2269,11 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/my/rotations' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const sc = siteConfig(); const hosts = String(sc.linkDomains || '').split(',').map(x => x.trim()).filter(Boolean);
return json(res, 200, { rotations: await rotator.list(s.email), hosts: hosts.length ? hosts : [SITE_HOST] }, { 'Cache-Control': 'no-store' });
return json(res, 200, { rotations: await rotator.list(s.email), hosts: hosts.length ? hosts : [SITE_HOST], tier: await toolTier(s.email) }, { 'Cache-Control': 'no-store' });
}
if (p === '/api/my/rotations' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
{ const t = await toolTier(s.email); const have = (await rotator.list(s.email)).length; if (have >= t.max) return json(res, 400, { error: toolCapError('spin links', have, t), tier: t }); }
const r = await rotator.create(s.email, await readBody(req)); return json(res, r.error ? 400 : 200, r);
}
m = /^\/api\/my\/rotations\/(\d+)$/.exec(p);
@@ -2395,7 +2421,7 @@ const server = http.createServer(async (req, res) => {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const hosts = domains.live(); // burned or reserve domains are never handed out for new pages
const ph = pagesHost(); const pageBase = ph ? 'https://' + ph + '/' : 'https://' + (hosts[0] || SITE_HOST) + '/p/';
return json(res, 200, { pages: await pages.list(s.email), hosts: ph ? [ph] : (hosts.length ? hosts : [SITE_HOST]), pageBase, types: pages.TYPES, styles: require('./pagestyle').catalog(), providers: pages.providers(), images: await pages.images(s.email), imageMax: pages.IMG_MAX, imageBytes: pages.IMG_BYTES }, { 'Cache-Control': 'no-store' });
return json(res, 200, { pages: await pages.list(s.email), hosts: ph ? [ph] : (hosts.length ? hosts : [SITE_HOST]), pageBase, types: pages.TYPES, styles: require('./pagestyle').catalog(), providers: pages.providers(), images: await pages.images(s.email), imageMax: pages.IMG_MAX, imageBytes: pages.IMG_BYTES , tier: await toolTier(s.email) }, { 'Cache-Control': 'no-store' });
}
if (p === '/api/my/pages/upload' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
@@ -2425,6 +2451,7 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/my/pages' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
{ const t = await toolTier(s.email); const have = (await pages.list(s.email)).length; if (have >= t.max) return json(res, 400, { error: toolCapError('pages', have, t), tier: t }); }
const r = await pages.create(s.email, await readBody(req)); return json(res, r.error ? 400 : 200, r);
}
if (p === '/api/my/pages/scan' && req.method === 'POST') {