Partner links for ViralAdSource: PARTNER_LINKS vas (the vab wiring)

/api/partner/vas/links serves ViralAdSource the same way as vab: ensure / stats / spins, tagged vas:<ad id>, on the member's own
"ViralAdSource" network source (new catalog template viraladsource, NET_SRC vas + viraladsource). qa/partner-vaslinks.test.mjs
(16 checks, incl. account by network username and vab/vas/dh kept apart); vab, dh, spins, netsrc, netconv, housespins green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 05:27:27 -06:00
parent 6c5851b4d5
commit 77e18fd230
5 changed files with 106 additions and 4 deletions
+30
View File
@@ -141,6 +141,36 @@
"verified": true,
"source": "network"
},
{
"key": "viraladsource",
"name": "ViralAdSource",
"site": "viraladsource.com",
"costModel": "",
"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 ViralAdSource (its footer, its promo kit) carry ?src=viraladsource and are counted under this source automatically. Your own ViralAdSource 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"
},
{
"key": "5xyourteam",
"name": "5xYourTeam",
+70
View File
@@ -0,0 +1,70 @@
// ViralAdSource tracked text-ad links (/api/partner/vas/links, 2026-11-17; the vab wiring with site vas). Same checks as
// partner-vablinks.test.mjs, plus account by network username (ViralAdSource sends no email) and the 'spins' list.
// 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 "ViralAdSource" 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-vaslinks.test.mjs (from the site dir; PORT default 8976)
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 || 8976); 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(), 'vas-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 = 'vas') {
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 === 'viraladsource' && mine[0].name === 'ViralAdSource' && r.sourceId === mine[0].id, 'the account has one "ViralAdSource" 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 === 'vas:42' && rot[0].name === 'ViralAdSource: Grow your list' && rot[0].sourceId === mine[0].id && rot[0].destinations[0].url === AD[0].url, 'the link is tagged vas: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));
r = await call({ username: 'dhone', op: 'ensure', links: [{ id: '42', name: 'Grow your list', url: 'https://mylist.example.org/?ref=one&v=2' }] });
ok(r.account && r.username === 'dhone' && r.links['42'] && r.links['42'].code === c42, 'by network username (no email): the same link', r);
r = await call({ username: 'dhone', op: 'spins' });
ok(r.account && Array.isArray(r.spins) && r.spins.every(x => x.code !== c42) && Array.isArray(r.hosts) && r.hosts.includes('spin-links.test.org'), 'spins by username leave the partner links out and list the hosts', r);
const vab = await call({ email: 'one@dh.test', op: 'stats' }, {}, 'vab');
ok(vab.account && Object.keys(vab.stats).length === 0, 'vab stats do not see vas links', vab.stats);
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, 'vas stats: the ad click, only the vas 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 vas 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 === 'vas:42').id);
ok(rep && rep.sr === mine[0].id && rep.q && rep.q.s1 === '42', 'the click is recorded under the ViralAdSource 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);
+1
View File
@@ -111,6 +111,7 @@ elif [ "$MODE" = "netsrc" ]; then
node qa/partner-dhlinks.test.mjs || status=1
node qa/partner-vablinks.test.mjs || status=1
node qa/partner-vabspins.test.mjs || status=1
node qa/partner-vaslinks.test.mjs || status=1
elif [ "$MODE" = "lsid" ]; then
node qa/lsid-pixel.test.mjs || status=1
elif [ "$MODE" = "kb" ]; then
+4 -3
View File
@@ -1448,7 +1448,8 @@ function curtained(req, res, u) {
}
// partner sites allowed on /api/partner/<site>/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 PARTNER_LINKS = { dh: { template: 'downlinehydra', name: 'DownlineHydra' }, vab: { template: 'viraladblitz', name: 'ViralAdBlitz' },
vas: { template: 'viraladsource', name: 'ViralAdSource' } }; // vas = ViralAdSource text ads (Marty 2026-11-17), the vab wiring
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 {
@@ -3202,8 +3203,8 @@ const server = http.createServer(async (req, res) => {
}
return json(res, 200, out, { 'Cache-Control': 'no-store' });
}
// -- Partner tracked links (Marty 2026-11-15): /api/partner/<site>/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 tracked links (Marty 2026-11-15): /api/partner/<site>/links, site = dh (DownlineHydra program links), vab (ViralAdBlitz
// text ads, the ad id as sub-id) or vas (ViralAdSource text ads, the same as vab). 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
+1 -1
View File
@@ -143,7 +143,7 @@ function meta(owner) { const m = {}; for (const s of mine(owner)) m[s.id] = { na
// source for that site, made from the network catalog template the first time it is needed. Only network templates qualify.
const NET_SRC = { iap: 'instantadpay', instantadpay: 'instantadpay', linkspin: 'linkspin', dlb: 'downlinebanners', downlinebanners: 'downlinebanners',
vbb: 'viralbannerblitz', viralbannerblitz: 'viralbannerblitz', stackpol: 'stackpol', earnerscorner: 'earnerscorner',
dh: 'downlinehydra', downlinehydra: 'downlinehydra', vab: 'viraladblitz', viraladblitz: 'viraladblitz', fivex: '5xyourteam', '5xyourteam': '5xyourteam' };
dh: 'downlinehydra', downlinehydra: 'downlinehydra', vab: 'viraladblitz', viraladblitz: 'viraladblitz', vas: 'viraladsource', viraladsource: 'viraladsource', fivex: '5xyourteam', '5xyourteam': '5xyourteam' };
function networkTemplate(src) { const k = NET_SRC[String(src || '').trim().toLowerCase()]; const t = k ? template(k) : null; return t && t.source === 'network' ? t : null; }
function networkSource(owner, src) {
const t = networkTemplate(src); if (!t || !owner) return null;