From 6607e39e307d6e56bcb4ebccac0937bc379b061e Mon Sep 17 00:00:00 2001 From: martbost Date: Sun, 15 Nov 2026 06:20:23 -0600 Subject: [PATCH] Partner tracked links generalized (2026-11-15): POST /api/partner//links for site dh (DownlineHydra programs) or vab (ViralAdBlitz text ads, the ad id as s1/placement). PARTNER_LINKS maps each site to its network template + link name; keys dh: / vab: keep the two apart; items take program or id. Catalog viraladblitz template gains clickid/placement/s1 params. qa/partner-vablinks.test.mjs 13/13 (signature, unknown site refused, source, edit keeps the code, dh vs vab apart, stats per site); run.sh netsrc runs netsrc 17/17 + partner-dhlinks 13/13 + partner-vablinks 13/13. LOCAL ONLY. Co-Authored-By: Claude Opus 5.5 --- catalog/traffic-sources.json | 23 +++++++++++-- qa/partner-vablinks.test.mjs | 63 ++++++++++++++++++++++++++++++++++++ qa/run.sh | 4 ++- server.js | 21 ++++++++---- 4 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 qa/partner-vablinks.test.mjs diff --git a/catalog/traffic-sources.json b/catalog/traffic-sources.json index a57fc5f..0bb5599 100644 --- a/catalog/traffic-sources.json +++ b/catalog/traffic-sources.json @@ -116,9 +116,28 @@ "name": "ViralAdBlitz", "site": "viraladblitz.com", "costModel": "", - "params": [], + "params": [ + { + "key": "clickid", + "token": "{clickid}", + "label": "Click id", + "role": "externalId" + }, + { + "key": "placement", + "token": "{ad}", + "label": "Text ad", + "role": "param" + }, + { + "key": "s1", + "token": "{ad}", + "label": "Text ad (sub-id)", + "role": "param" + } + ], "postbackUrl": "", - "notes": "Crypto Team Build Network text-ad site. Clicks that arrive from ViralAdBlitz (its footer, its promo kit) carry ?src=viraladblitz and are counted under this source automatically.", + "notes": "Crypto Team Build Network text-ad site. Clicks that arrive from ViralAdBlitz (its footer, its promo kit) carry ?src=viraladblitz and are counted under this source automatically. Your own ViralAdBlitz text ad goes out as a LinkSpin link on your account: every click carries the ad id as placement and s1.", "verified": true, "source": "network" }, diff --git a/qa/partner-vablinks.test.mjs b/qa/partner-vablinks.test.mjs new file mode 100644 index 0000000..c89e960 --- /dev/null +++ b/qa/partner-vablinks.test.mjs @@ -0,0 +1,63 @@ +// ViralAdBlitz tracked text-ad links (/api/partner/vab/links, 2026-11-15; the same endpoint as DownlineHydra's, site vab). +// Boots server.js on its own port with a throwaway seeded data dir (JSON store, no DB, no mail key, no chain keys) and checks: +// the signature, one link per text ad on the member's own account with the "ViralAdBlitz" source and the ad id as sub-id, an edited +// ad link updating the same code, a DownlineHydra link with the same id kept apart, stats per site, unknown partner sites refused. +// node qa/partner-vablinks.test.mjs (from the site dir; PORT default 8974) +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import crypto from 'node:crypto'; +import { spawn } from 'node:child_process'; + +const PORT = Number(process.env.PORT || 8974); const BASE = 'http://127.0.0.1:' + PORT; const SEC = crypto.randomBytes(32).toString('hex'); +let pass = 0, fail = 0; const ok = (c, what, x) => { if (c) { pass++; console.log(' ok ' + what); } else { fail++; console.log(' FAIL ' + what + (x !== undefined ? ' -> ' + JSON.stringify(x).slice(0, 400) : '')); } }; +const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'vab-qa-')); +const now = Date.now(); +const acct = (email, username, memberId) => ({ email, username, code: username.slice(0, 7), memberId, created: now - 86400000, sponsorRef: '' }); +const accounts = { v: 2, byEmail: { 'one@dh.test': acct('one@dh.test', 'dhone', 920001), 'two@dh.test': acct('two@dh.test', 'dhtwo', 920002) }, byAddress: {}, byCode: {}, joins: 2, positions: {} }; +for (const a of Object.values(accounts.byEmail)) accounts.byCode[a.code] = a.email; +fs.writeFileSync(path.join(DATA, 'accounts.json'), JSON.stringify(accounts)); +fs.writeFileSync(path.join(DATA, 'site.json'), JSON.stringify({ linkDomains: 'spin-links.test.org' })); +const env = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, NETWORK_SSO_SECRET: SEC, ADMIN_PASSWORD: 'x'.repeat(16), ADMIN_EMAIL: 'admin@dh.test' }); +for (const k of ['NODE_ENV', 'DATABASE_URL', 'ENGINE_KEY', 'LS_SYNC_SECRET', 'OUTBOUND', 'LS_TESTERS', 'CURTAIN', 'HUB_ENABLED', 'HUB_URL']) delete env[k]; +const site = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..'); +const srv = spawn(process.execPath, ['server.js'], { cwd: site, env, stdio: ['ignore', 'ignore', 'ignore'] }); +const sleep = ms => new Promise(r => setTimeout(r, ms)); +async function call(body, o = {}, site = 'vab') { + const raw = JSON.stringify(body); const ts = String(o.ts || Date.now()); const sig = crypto.createHmac('sha256', o.sec || SEC).update('net.v1.' + ts + '\n' + raw).digest('hex'); + const r = await fetch(BASE + '/api/partner/' + site + '/links', { method: 'POST', body: raw, headers: { 'Content-Type': 'application/json', 'X-Net-Ts': ts, 'X-Net-Sig': sig } }); + return Object.assign({ _status: r.status }, await r.json().catch(() => ({}))); +} +try { + for (let i = 0; i < 60; i++) { try { if ((await fetch(BASE + '/api/config')).ok) break; } catch (e) {} await sleep(500); } + const AD = [{ id: '42', name: 'Grow your list', url: 'https://mylist.example.org/?ref=one' }]; + let r = await call({ email: 'one@dh.test', op: 'ensure', links: AD }, { sec: 'y'.repeat(64) }); ok(r._status === 401, 'a wrong signature is refused'); + r = await call({ email: 'one@dh.test', op: 'ensure', links: AD }, {}, 'zz'); ok(r._status === 404 || (r._status >= 400 && !r.links), 'an unknown partner site is not served', r); + r = await call({ email: 'nobody@dh.test', op: 'ensure', links: AD }); ok(r._status === 200 && r.account === false, 'no LinkSpin account: account false', r); + r = await call({ email: 'one@dh.test', op: 'ensure', links: AD }); + const c42 = r.links && r.links['42'] && r.links['42'].code; + ok(r.account && r.host === 'spin-links.test.org' && /^[a-z0-9]{6}$/.test(c42 || '') && r.links['42'].created, 'ensure: a new link for the ad (id field), clean host', r); + ok(r.links['42'].link === 'https://spin-links.test.org/r/' + c42 + '?s1=42&placement=42', 'the link carries the ad id as s1 and placement', r.links['42'].link); + const src = JSON.parse(fs.readFileSync(path.join(DATA, 'sources.json'), 'utf8')); const mine = (src.items || src.sources || []).filter(x => x.owner === 'one@dh.test'); + ok(mine.length === 1 && mine[0].template === 'viraladblitz' && mine[0].name === 'ViralAdBlitz' && r.sourceId === mine[0].id, 'the account has one "ViralAdBlitz" source (network template)', mine); + let rot = JSON.parse(fs.readFileSync(path.join(DATA, 'rotator.json'), 'utf8')).rotations.filter(x => x.owner === 'one@dh.test'); + ok(rot.length === 1 && rot[0].partner === 'vab:42' && rot[0].name === 'ViralAdBlitz: Grow your list' && rot[0].sourceId === mine[0].id && rot[0].destinations[0].url === AD[0].url, 'the link is tagged vab:42 with that source and points at the ad link', rot); + r = await call({ email: 'one@dh.test', op: 'ensure', links: [{ id: '42', name: 'Grow your list', url: 'https://mylist.example.org/?ref=one&v=2' }] }); + rot = JSON.parse(fs.readFileSync(path.join(DATA, 'rotator.json'), 'utf8')).rotations.filter(x => x.owner === 'one@dh.test'); + ok(r.links['42'].code === c42 && !r.links['42'].created && rot.length === 1 && rot[0].destinations[0].url.endsWith('&v=2'), 'an edited ad link updates the same LinkSpin link', r); + r = await call({ email: 'one@dh.test', op: 'ensure', links: [{ program: '42', url: 'https://other.example.org/' }] }, {}, 'dh'); + rot = JSON.parse(fs.readFileSync(path.join(DATA, 'rotator.json'), 'utf8')).rotations.filter(x => x.owner === 'one@dh.test'); + ok(r.links['42'] && r.links['42'].code !== c42 && rot.length === 2 && rot.some(x => x.partner === 'dh:42'), 'a DownlineHydra program with the same id is a separate link', rot.map(x => x.partner)); + const hit = await fetch(BASE + '/r/' + c42 + '?s1=42&placement=42', { redirect: 'manual', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/130.0 Safari/537.36' } }); + const loc = hit.headers.get('location') || ''; + ok(hit.status >= 300 && hit.status < 400 && loc.startsWith('https://mylist.example.org/?ref=one&v=2'), 'the redirect lands on the ad link', [hit.status, loc]); + await sleep(300); + r = await call({ email: 'one@dh.test', op: 'stats' }); + ok(r.account && r.stats['42'] && r.stats['42'].hits === 1 && r.stats['42'].unique30 === 1 && Object.keys(r.stats).length === 1, 'vab stats: the ad click, only the vab links', r.stats); + r = await call({ email: 'one@dh.test', op: 'stats' }, {}, 'dh'); + ok(r.account && r.stats['42'] && r.stats['42'].hits === 0, 'dh stats do not see the vab click', r.stats); + const rep = JSON.parse(fs.readFileSync(path.join(DATA, 'rotator.json'), 'utf8')).hits.find(h => h.r === rot.find(x => x.partner === 'vab:42').id); + ok(rep && rep.sr === mine[0].id && rep.q && rep.q.s1 === '42', 'the click is recorded under the ViralAdBlitz source with the ad sub-id', rep); +} catch (e) { fail++; console.error(e); } +finally { srv.kill(); await sleep(300); try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} } +console.log('\n' + pass + ' passed, ' + fail + ' failed'); process.exit(fail ? 1 : 0); diff --git a/qa/run.sh b/qa/run.sh index d42ec11..572100c 100644 --- a/qa/run.sh +++ b/qa/run.sh @@ -9,7 +9,7 @@ # bash qa/run.sh sponsorfollow # sponsor follow rule + network tank unit tests + carry hold guard + carry activation regression # bash qa/run.sh tankhold # holding tank: network alignment first, plain-activation hold (never a purchase), 24-hour rotation, payouts on at assignment (unit with a mocked clock + fake engine, then a local copy with a mock InstantAdPay) # bash qa/run.sh netconv # conversion linkage: InstantAdPay's joins, wallets, purchases counted once, own account left out, window, aged hits, two copies racing, one Reports list, the landing tag on network links -# bash qa/run.sh netsrc # network sites as traffic sources: the six fixed network links, ?src= picks the sending site's source, member links get it on first use +# bash qa/run.sh netsrc # network sites as traffic sources: the seven fixed network links, ?src= picks the sending site's source, member links get it on first use; partner tracked links (DownlineHydra programs, ViralAdBlitz text ads) # bash qa/run.sh lsid # page-builder lead -> rotator conversion + postback, audience pixel events and cookieless hits # bash qa/run.sh convpixel # conversion pixel: ad click ids, landing tag + goal pixel (url/stored/cookie/soft), dedupe, window, owner check, cost per goal, IAP partner calls, browser + framed # bash qa/run.sh nas # Network Ad Space billing: stop snapshot, active-only reconcile, restart without phantom delivery, the 1/N network + partner-zone rate (stubbed NAS, throwaway data) @@ -100,6 +100,8 @@ elif [ "$MODE" = "netconv" ]; then node qa/netconv.test.mjs || status=1 elif [ "$MODE" = "netsrc" ]; then node qa/netsrc.test.mjs || status=1 + node qa/partner-dhlinks.test.mjs || status=1 + node qa/partner-vablinks.test.mjs || status=1 elif [ "$MODE" = "lsid" ]; then node qa/lsid-pixel.test.mjs || status=1 elif [ "$MODE" = "kb" ]; then diff --git a/server.js b/server.js index bd3b7c5..548c4c8 100644 --- a/server.js +++ b/server.js @@ -1428,6 +1428,8 @@ function curtained(req, res, u) { return true; } +// partner sites allowed on /api/partner//links (2026-11-15): network catalog template + the name the member sees on the link +const PARTNER_LINKS = { dh: { template: 'downlinehydra', name: 'DownlineHydra' }, vab: { template: 'viraladblitz', name: 'ViralAdBlitz' } }; const server = http.createServer(async (req, res) => { { const t0 = Date.now(); res.on('finish', () => { const ms = Date.now() - t0; if (ms > 3000) console.warn('slow request', req.method, String(req.url || '').split('?')[0].slice(0, 80), ms + 'ms', res.statusCode); }); } // visibility for member-felt delays (2026-10-12) try { @@ -3130,14 +3132,19 @@ const server = http.createServer(async (req, res) => { } return json(res, 200, out, { 'Cache-Control': 'no-store' }); } - // -- DownlineHydra tracked program links (Marty 2026-11-15). Same net.v1 signature as the Banner Spins call above. A DownlineHydra + // -- Partner tracked links (Marty 2026-11-15): /api/partner//links, site = dh (DownlineHydra program links) or vab (ViralAdBlitz + // text ads, the ad id as sub-id). PARTNER_LINKS names each site's network template and link name. Below, "program" = the + // partner's item id (a DownlineHydra program, a ViralAdBlitz ad). + // DownlineHydra tracked program links (Marty 2026-11-15). Same net.v1 signature as the Banner Spins call above. A DownlineHydra // member saved a referral link for an outside program (a wild head or a my head); their downline sees a LinkSpin link for it // on this member's own account, tagged with the account's "DownlineHydra" source and the program id as a sub-id // (?s1=&placement=, so Reports split clicks by program). Only clean link domains (domains.hosts()). // { email, username?, op: 'ensure', links: [{ program, name, url }] } -> { account, username, host, links: { program: { code, link } }, errors } // { email, username?, op: 'stats' } -> { account, host, stats: { program: { code, link, hits, hits30, unique30 } } } // Nothing else about the account is read or changed. - if (p === '/api/partner/dh/links' && req.method === 'POST') { + const plm = req.method === 'POST' ? /^\/api\/partner\/([a-z]{2,8})\/links$/.exec(p) : null; + if (plm && PARTNER_LINKS[plm[1]]) { + const PL = PARTNER_LINKS[plm[1]]; const pfx = plm[1] + ':'; let raw = ''; try { raw = await new Promise((ok, no) => { let d = ''; req.on('data', c => { d += c; if (d.length > 65536) { req.destroy(); no(new Error('too big')); } }); req.on('end', () => ok(d)); req.on('error', no); }); } catch (e) { return json(res, 400, { error: 'bad body' }); } const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); const ts = String(req.headers['x-net-ts'] || ''); const sig = String(req.headers['x-net-sig'] || ''); if (sec.length < 32 || !/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 300000) return json(res, 401, { error: 'unauthorized' }); @@ -3152,16 +3159,16 @@ const server = http.createServer(async (req, res) => { const host = hs[0].host; const PID = /^[a-z0-9_-]{1,40}$/i; const linkOf = (code, pid) => 'https://' + host + '/r/' + code + '?s1=' + encodeURIComponent(pid) + '&placement=' + encodeURIComponent(pid); if (b.op === 'stats') { - const st = rotator.partnerStats(a.email, 'dh:'); const out = {}; - for (const [k, v] of Object.entries(st)) { const pid = k.slice(3); out[pid] = { code: v.code, link: linkOf(v.code, pid), hits: v.hits, hits30: v.hits30, unique30: v.unique30 }; } + const st = rotator.partnerStats(a.email, pfx); const out = {}; + for (const [k, v] of Object.entries(st)) { const pid = k.slice(pfx.length); out[pid] = { code: v.code, link: linkOf(v.code, pid), hits: v.hits, hits30: v.hits30, unique30: v.unique30 }; } return json(res, 200, { account: true, username: a.username || null, host, stats: out }, { 'Cache-Control': 'no-store' }); } if (b.op !== 'ensure' || !Array.isArray(b.links) || !b.links.length || b.links.length > 60) return json(res, 400, { error: 'op' }); - const src = sources.networkSource(a.email, 'downlinehydra'); + const src = sources.networkSource(a.email, PL.template); const links = {}, errors = {}; for (const x of b.links) { - const pid = String((x && x.program) || ''); if (!PID.test(pid)) { errors[pid.slice(0, 40) || '?'] = 'program'; continue; } - const r = rotator.ensurePartner(a.email, 'dh:' + pid, 'DownlineHydra: ' + String(x.name || pid).slice(0, 60), String(x.url || ''), src ? src.id : null); + const pid = String((x && (x.program || x.id)) || ''); if (!PID.test(pid)) { errors[pid.slice(0, 40) || '?'] = 'program'; continue; } + const r = rotator.ensurePartner(a.email, pfx + pid, PL.name + ': ' + String(x.name || pid).slice(0, 60), String(x.url || ''), src ? src.id : null); if (r.error) errors[pid] = r.error; else links[pid] = { code: r.code, link: linkOf(r.code, pid), created: r.created }; } return json(res, 200, { account: true, username: a.username || null, host, sourceId: src ? src.id : null, links, errors }, { 'Cache-Control': 'no-store' });