a8a1a8eec7
Plant a program free (referral link with {id}, link check green / yellow / red, daily recheck, reports), members save their
referral IDs in its packet, a sponsor-first link (member page / ?r= / the hub sponsor line, then the planter), the sprout meter
to REVIEW_SAVES (DEFAULT 25) -> Marty's review queue -> approved packets exported for the CTB builder / DownlineHydra wild heads
with every saved ID. Dormant old programs confirmed by their owner, old-link redirects (oldrefs), Spotlight on YPBShop (NOT
deployed; DEFAULT $10 / 1,000 views, 20/5/5/5/5, company 60), verified views with Spotlight delivery, trust pack (ledger,
contract, toasts, Telegram card, terms / disclaimer / privacy, TrustClickz only), network footer row, chatbot, promo kit,
Guides, PolHunter slot, LinkSpin tracked-link and zone hooks, AI writer through the hub. Seed-catalog look from the approved
mockup. Tests: qa/unit.test.cjs 33/33, qa/e2e.mjs 121/121 on a local anvil chain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
8.8 KiB
JavaScript
116 lines
8.8 KiB
JavaScript
// The Seed Bed rules: planting, saved IDs, the sprout meter, the review stage, the sponsor-first link and the transplant export.
|
|
// Data lives in store.js; the HTTP side is in server.js. Parts reused on purpose:
|
|
// myheads.js (DownlineHydra, unit-tested there): the link and text checks for a member-added program
|
|
// wild.js (DownlineHydra): a pasted whole referral link -> the ID in it (cleanId), the plain home page (homeUrl)
|
|
//
|
|
// Packet lifecycle
|
|
// status: live | held (yellow or red link, or reported: Marty's queue) | removed | dormant (an old YourProgramBuilder program
|
|
// waiting for its owner to confirm it)
|
|
// stage: sprouting -> review (REVIEW_SAVES saves from distinct confirmed network members) -> approved (transplanted: exported
|
|
// for the CTB builder and DownlineHydra) | rejected (stays in the Seed Bed, can sprout on; Marty may look again later)
|
|
// A packet is shown in the bed only while it is live and its link check is green, or yellow and approved by Marty for exactly
|
|
// the text he saw (an edit sends it back to the queue).
|
|
'use strict';
|
|
const crypto = require('crypto');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const store = require('./store');
|
|
const myheads = require('./myheads');
|
|
const wild = require('./wild');
|
|
const cfgMod = require('./config');
|
|
|
|
const C = () => cfgMod.get();
|
|
const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
const COSTS = ['free', 'paid'];
|
|
const lc = v => String(v || '').toLowerCase();
|
|
|
|
// the CTB builder snapshot DownlineHydra reads (seed/builder.seed.json, 46 programs 11-14): a program already there is not planted
|
|
// again here (its members save their IDs on DownlineHydra's wild heads)
|
|
let builder = null;
|
|
function builderList() {
|
|
if (builder) return builder;
|
|
let d = { programs: [], cats: [] };
|
|
try { d = JSON.parse(fs.readFileSync(path.join(__dirname, 'seed', 'builder.seed.json'), 'utf8')); } catch (e) {}
|
|
const progs = (d.programs || []).filter(p => !p.network);
|
|
builder = { cats: (d.cats || []).filter(c => String(c.id) !== '12'), hosts: [...new Set(progs.map(p => myheads.hostOf(p.url.replace(/\{affil[a-z]*id\}\.?/gi, ''))).filter(Boolean))] };
|
|
return builder;
|
|
}
|
|
const cats = () => builderList().cats;
|
|
|
|
const textHash = p => crypto.createHash('sha256').update([p.name, p.url, p.desc, p.cost, p.costText, p.contract].join('\n')).digest('hex').slice(0, 16);
|
|
|
|
// the planting form -> { error, field } | { ok, fields, flags }
|
|
function validatePlant(b) {
|
|
const L = C().packet;
|
|
const v = myheads.validate({ name: b.name, url: b.url, desc: b.desc, myId: b.myId, cat: b.cat }, { limits: { name: L.name, desc: L.desc }, wildHosts: builderList().hosts, cats: cats() });
|
|
if (v.error) {
|
|
if (v.wild) return { error: 'That program is already in the Crypto Team Build Network builder. Save your ID for it on DownlineHydra\'s wild heads instead.', field: 'url', wild: true };
|
|
return v;
|
|
}
|
|
if (!v.head.template) return { error: 'Put {id} in the link where the referral ID goes (for example https://program.example/?ref={id}), so every member can save their own ID.', field: 'url' };
|
|
if (v.head.desc.length < 10) return { error: 'Say in a sentence what the program is (10 to ' + L.desc + ' characters).', field: 'desc' };
|
|
const cost = COSTS.includes(String(b.cost)) ? String(b.cost) : null;
|
|
if (!cost) return { error: 'Say whether the program is free to join or costs money to join.', field: 'cost' };
|
|
const costText = String(b.costText == null ? '' : b.costText).replace(/[\u0000-\u001f\u007f<>]/g, ' ').replace(/[–—]/g, '-').replace(/\s+/g, ' ').trim().slice(0, L.cost + 1);
|
|
if (costText.length > L.cost) return { error: 'Keep the cost note to ' + L.cost + ' characters.', field: 'costText' };
|
|
if (cost === 'paid' && costText.length < 2) return { error: 'Say what it costs to join (for example "$10 one-time" or "from 25 POL").', field: 'costText' };
|
|
let contract = String(b.contract || '').trim();
|
|
if (contract && !ADDR_RE.test(contract)) return { error: 'The contract address must be 0x followed by 40 letters or numbers. Leave it empty if the program has no contract.', field: 'contract' };
|
|
contract = contract.toLowerCase();
|
|
const flags = v.flags.slice();
|
|
if (/\b(guaranteed|passive income|daily (profit|returns?)|\d+x your|roi)\b/i.test(v.head.name + ' ' + v.head.desc + ' ' + costText)) flags.push('income claim words');
|
|
return { ok: true, fields: { name: v.head.name, url: v.head.url, template: true, ownerId: v.head.myId, desc: v.head.desc, cat: v.head.cat, host: v.head.host, cost, costText: cost === 'paid' ? costText : '', contract }, flags };
|
|
}
|
|
|
|
// an ID a member types (or a whole referral link they paste) -> the clean ID, '' (remove), or null (not an ID for this packet)
|
|
const asWild = p => ({ url: String(p.url).replace(/\{id\}/g, '{affiliateid}'), idKind: 'path' });
|
|
function cleanId(p, raw) { return wild.cleanId(asWild(p), raw); }
|
|
const fill = (p, id) => String(p.url).replace(/\{id\}/g, encodeURIComponent(String(id)));
|
|
const homeUrl = p => wild.homeUrl(asWild(p));
|
|
|
|
const shown = p => !!p && p.status === 'live' && p.check && (p.check.state === 'green' || (p.check.state === 'yellow' && p.yellowOk === textHash(p)));
|
|
const confirmed = addr => { const m = store.member(addr); return !!(m && m.netOk === true && !m.blocked); };
|
|
// the sprout meter: saved IDs from distinct confirmed network members (the planter's own ID counts as one)
|
|
function sprouts(p) { const seen = new Set(); for (const s of store.savesOf(p.id)) if (s.refId && confirmed(s.owner)) seen.add(s.hubId || s.owner); if (p.owner && p.ownerId && confirmed(p.owner)) seen.add((store.member(p.owner) || {}).hubId || p.owner); return seen.size; }
|
|
// after any save: a sprouting packet that reached the threshold moves to Marty's review queue (it keeps sprouting while it waits)
|
|
function grow(p) {
|
|
const n = sprouts(p); p.sprouts = n;
|
|
if ((p.stage || 'sprouting') === 'sprouting' && n >= C().reviewSaves) { p.stage = 'review'; p.reviewAt = Date.now(); store.savePacket(p); return { review: true, n }; }
|
|
store.savePacket(p); return { review: false, n };
|
|
}
|
|
|
|
// the one link a visitor sees: the nearest person in `chain` who saved an ID here, else the planter's ID, else the plain home page.
|
|
// chain = [{ wallet, username, depth }] nearest first (a member page / ?ref= visitor: that member first at depth 0; a signed-in
|
|
// member: their sponsor at depth 1, ...)
|
|
function sponsorLink(p, chain) {
|
|
const byWallet = new Map(), byName = new Map();
|
|
for (const s of store.savesOf(p.id)) { if (!s.refId) continue; byWallet.set(s.owner, s); if (s.username) byName.set(lc(s.username), s); }
|
|
for (const c of chain || []) {
|
|
const s = (c.wallet && byWallet.get(lc(c.wallet))) || (c.username && byName.get(lc(c.username)));
|
|
if (s) return { url: fill(p, s.refId), by: s.username || null, depth: c.depth, fallback: null, save: s.id };
|
|
}
|
|
if (p.ownerId) return { url: fill(p, p.ownerId), by: p.ownerName || null, depth: null, fallback: 'planter', save: null };
|
|
return { url: homeUrl(p), by: null, depth: null, fallback: 'none', save: null };
|
|
}
|
|
|
|
// a packet as the public pages show it (never a wallet, never anyone's saved ID except through the click relay)
|
|
function card(p, extra) {
|
|
const n = p.sprouts != null ? p.sprouts : sprouts(p);
|
|
return Object.assign({ id: p.id, no: String(p.id).padStart(3, '0'), name: p.name, desc: p.desc, host: p.host, cost: p.cost, costText: p.costText || '', contract: p.contract || null,
|
|
cat: p.cat, sownAt: p.createdAt, planter: p.ownerName || null, saves: n, need: C().reviewSaves, stage: p.stage || 'sprouting', check: p.check ? p.check.state : null,
|
|
checkedAt: p.check ? p.check.at : null, clicks: p.vclicks || 0, href: '/p/' + p.id }, extra || {});
|
|
}
|
|
|
|
// approved packets for the Crypto Team Build Network builder / DownlineHydra's wild heads, every saved ID carried over.
|
|
// The link is given in the builder's own form ({affiliateid}). Saved IDs of blocked or unconfirmed people are left out.
|
|
function exportPacket(p) {
|
|
const ids = [];
|
|
for (const s of store.savesOf(p.id)) { if (!s.refId || !confirmed(s.owner)) continue; const m = store.member(s.owner) || {}; ids.push({ username: m.username || s.username || null, hubId: m.hubId || s.hubId || null, refId: s.refId, savedAt: s.at }); }
|
|
const pm = p.owner ? store.member(p.owner) || {} : {};
|
|
if (p.ownerId && !ids.some(x => x.hubId && x.hubId === pm.hubId)) ids.unshift({ username: pm.username || p.ownerName || null, hubId: pm.hubId || null, refId: p.ownerId, savedAt: p.createdAt, planter: true });
|
|
return { ypbId: p.id, name: p.name, url: asWild(p).url, idKind: 'path', desc: p.desc, cat: p.cat, host: p.host, cost: p.cost, costText: p.costText || '', contract: p.contract || null,
|
|
planter: { username: pm.username || p.ownerName || null, hubId: pm.hubId || null }, approvedAt: p.decidedAt || null, note: p.decidedNote || '', ids };
|
|
}
|
|
|
|
module.exports = { validatePlant, cleanId, fill, homeUrl, shown, sprouts, grow, sponsorLink, card, exportPacket, textHash, cats, builderList, confirmed, COSTS };
|