c65e57dadc
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
185 lines
17 KiB
JavaScript
185 lines
17 KiB
JavaScript
// Promo days (Marty 2026-11-17, "Network Weekend", Black Friday to Cyber Monday 2026): a reusable date-to-percent bonus map, cloned
|
|
// from Five Dollar Friday (friday.js). Any package bought on a mapped Central day, at or above that day's minimum, earns that day's
|
|
// bonus percent of its on-chain credits (purchased-grade, labelled in the credit log), once per purchase tx across app copies
|
|
// (marks.js, MySQL), with a purchase notice that names the day. Future holidays = a new map in the promoDays setting, no code.
|
|
//
|
|
// The 2026 map (DEFAULT_DAYS): Fri 11-27 Black Friday +40% $5+, Sat 11-28 and Sun 11-29 +20% $5+, Mon 11-30 Cyber Monday +30% $20+.
|
|
// Each day is midnight to midnight Central. A mapped day that is a Friday is paid by friday.js at max(fridayBonusPct, the day's pct)
|
|
// (fridayPct below), so Black Friday is ONE bonus per tx at 40%, the free 7-day Game Pass perk still fires, and nobody flips
|
|
// fridayBonusPct by hand; normal Five Dollar Friday (+20%) resumes on 12-04 by itself.
|
|
//
|
|
// Also here, all date-gated to the weekend window (weekendStart..weekendEnd, Fri 11-27 00:00 CT to Tue 12-01 00:00 CT):
|
|
// - Weekend Starter Bundle: a $20+ pack also gets the LinkSpin code (setting weekendLinkspinCode, default WEEKEND500) in its notice
|
|
// - Builder Bundle: a $100+ pack is listed for DownlineHydra (GET /api/network/weekend-builders); DH grants Pro, 25 comps
|
|
// - Game Pass bonus days for tier passes fulfilled Fri 11-27 00:00 CT to Fri 12-04 00:00 CT (passBonusDays, read by gamepass.js)
|
|
// - the chatbot fact and answer, the /api/promodays view for the strip, Overview card and /weekend page
|
|
//
|
|
// Settings (siteConfig): promoDaysOn '1'|'0' (kill switch), promoDays (JSON {"YYYY-MM-DD": {pct, minCents, name}}), weekendStart /
|
|
// weekendEnd / weekendPassEnd (ISO), weekendLinkspinCode, weekendBuilderCap (24: DH keeperGrantsLeft 49 on 11-17, minus 5 PRO_PENDING, keeps a 20-grant reserve), promoMailBase (link base for emails, default the share domain instantadpay.link).
|
|
// Test clock: env IAP_TEST_NOW (ISO), ignored when NODE_ENV=production. Copy rules: no em dashes, Central times, no income promises.
|
|
'use strict';
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let X = {}, FILE = null, S = null;
|
|
const TZ = 'America/Chicago';
|
|
const dayOf = ts => new Date(ts).toLocaleDateString('en-CA', { timeZone: TZ });
|
|
const weekdayOf = ts => new Date(ts).toLocaleDateString('en-US', { timeZone: TZ, weekday: 'short' });
|
|
const CREDITS_LINE = 'Ad credits buy advertising, not income.';
|
|
|
|
const DEFAULT_DAYS = {
|
|
'2026-11-27': { pct: 40, minCents: 500, name: 'Black Friday' },
|
|
'2026-11-28': { pct: 20, minCents: 500, name: 'Network Weekend Saturday' },
|
|
'2026-11-29': { pct: 20, minCents: 500, name: 'Network Weekend Sunday' },
|
|
'2026-11-30': { pct: 30, minCents: 2000, name: 'Cyber Monday' }
|
|
};
|
|
const DEFAULTS = {
|
|
weekendStart: '2026-11-27T00:00:00-06:00', weekendEnd: '2026-12-01T00:00:00-06:00', weekendPassEnd: '2026-12-04T00:00:00-06:00',
|
|
weekendLinkspinCode: 'WEEKEND500', weekendStarterMinCents: 2000, weekendBuilderMinCents: 10000, weekendBuilderCap: 24,
|
|
passBonus: { explorer: 15, champion: 15, legend: 60 } // days on top of the tier's own (30, 30, 365)
|
|
};
|
|
|
|
function now() {
|
|
const o = process.env.NODE_ENV !== 'production' && process.env.IAP_TEST_NOW; const t = o ? Date.parse(o) : NaN;
|
|
return Number.isNaN(t) ? Date.now() : t;
|
|
}
|
|
function init(opts) { X = opts || {}; FILE = path.join(opts.dataDir, 'promodays.json'); S = load(); }
|
|
function load() { try { return Object.assign({ granted: {}, bundles: {} }, JSON.parse(fs.readFileSync(FILE, 'utf8'))); } catch (e) { return { granted: {}, bundles: {} }; } }
|
|
function save() { try { fs.writeFileSync(FILE, JSON.stringify(S)); } catch (e) {} }
|
|
async function claimOnce(key) { try { return X.marks ? await X.marks.claim(key) : true; } catch (e) { return true; } }
|
|
|
|
function cfg() {
|
|
const c = (X.siteConfig && X.siteConfig()) || {};
|
|
let days = DEFAULT_DAYS;
|
|
if (c.promoDays) { try { const j = typeof c.promoDays === 'string' ? JSON.parse(c.promoDays) : c.promoDays; if (j && typeof j === 'object') days = j; } catch (e) { console.error('promoDays setting is not valid JSON, using the built-in map'); } }
|
|
const ms = (k) => { const t = Date.parse(c[k] || DEFAULTS[k]); return Number.isNaN(t) ? Date.parse(DEFAULTS[k]) : t; };
|
|
return {
|
|
on: String(c.promoDaysOn == null ? '1' : c.promoDaysOn) === '1',
|
|
days, start: ms('weekendStart'), end: ms('weekendEnd'), passEnd: ms('weekendPassEnd'),
|
|
lsCode: String(c.weekendLinkspinCode || DEFAULTS.weekendLinkspinCode).toUpperCase().replace(/[^A-Z0-9_-]/g, '').slice(0, 24),
|
|
starterMin: Number(c.weekendStarterMinCents) || DEFAULTS.weekendStarterMinCents,
|
|
builderMin: Number(c.weekendBuilderMinCents) || DEFAULTS.weekendBuilderMinCents,
|
|
builderCap: Math.max(0, Number(c.weekendBuilderCap == null ? DEFAULTS.weekendBuilderCap : c.weekendBuilderCap) || 0),
|
|
mailBase: String(c.promoMailBase || 'https://instantadpay.link').replace(/\/+$/, ''), // instantadpay.com is on the Spamhaus DBL (still listed 2026-11-17): email links use the share domain
|
|
passBonus: DEFAULTS.passBonus,
|
|
tiersOn: String(c.sovTiers) === '1' // the tier passes are only on sale with sovTiers; the pass bonus days are only said while they are
|
|
};
|
|
}
|
|
// the mapped day at ts, or null: { day, pct, minCents, name }
|
|
function dayAt(ts) {
|
|
const c = cfg(); if (!c.on) return null;
|
|
const d = dayOf(ts); const e = c.days[d];
|
|
if (!e || !(Number(e.pct) > 0)) return null;
|
|
return { day: d, pct: Number(e.pct), minCents: Math.max(0, Number(e.minCents) || 0), name: String(e.name || 'Promo day').slice(0, 60) };
|
|
}
|
|
// friday.js asks: the promo percent for a Friday purchase (0 = none), so Black Friday is paid there, once, at the higher rate
|
|
function fridayPct(ts, cents) { const d = dayAt(ts); return d && weekdayOf(ts) === 'Fri' && (cents == null || cents >= d.minCents) ? d.pct : 0; }
|
|
function fridayName(ts) { const d = dayAt(ts); return d && weekdayOf(ts) === 'Fri' ? d.name : ''; }
|
|
function inWeekend(ts) { const c = cfg(); return c.on && ts >= c.start && ts < c.end; }
|
|
function weekendLive(t) { return inWeekend(t == null ? now() : t); }
|
|
// Game Pass bonus days for a tier pass fulfilled at ts (gamepass.js extend, via 'package' only; comps never get them)
|
|
function passBonusDays(tier, ts) {
|
|
const c = cfg(); if (!c.on || !(ts >= c.start && ts < c.passEnd)) return 0;
|
|
return Number(c.passBonus[tier]) || 0;
|
|
}
|
|
const usdOf = cents => ('$' + (cents / 100).toFixed(2)).replace(/\.00$/, '');
|
|
const tsOf = ev => (Number(ev.ts) > 1e12 ? Number(ev.ts) : (Number(ev.ts) > 0 ? Number(ev.ts) * 1000 : Date.now()));
|
|
|
|
// the bonus on a mapped non-Friday day (Fridays are paid by friday.js), and the bundle notices on any weekend day
|
|
async function onEvent(ev) {
|
|
if (!ev || ev.type !== 'Purchase') return null;
|
|
const ts = tsOf(ev); const cents = Number(ev.priceCents) || 0;
|
|
const out = { bonus: 0, starter: false, builder: false };
|
|
const d = dayAt(ts);
|
|
if (d && weekdayOf(ts) !== 'Fri' && cents >= d.minCents && !S.granted[ev.tx] && await claimOnce('pd:' + ev.tx)) {
|
|
const bonus = Math.round((Number(ev.creditAmount) || 0) * d.pct / 100);
|
|
const a = bonus > 0 && X.accounts ? await X.accounts.byMemberId(ev.buyerId) : null;
|
|
if (a && a.email) {
|
|
await X.ads.addEarned(a.email, bonus, { purchased: true, log: { kind: 'bonus', note: d.name + ': +' + d.pct + '% on your ' + usdOf(cents) + ' package', ref: 'pd:' + String(ev.tx).slice(0, 30) } });
|
|
S.granted[ev.tx] = { day: d.day, memberId: ev.buyerId, bonus, pct: d.pct, at: Date.now() }; save();
|
|
out.bonus = bonus;
|
|
try { await X.notify(ev.buyerId, d.name + ': +' + bonus + ' bonus credits', 'Your ' + usdOf(cents) + ' package landed on ' + d.name + ', so ' + bonus + ' bonus ad credits (+' + d.pct + '%) were added to your balance. ' + CREDITS_LINE + ' See your balance: https://instantadpay.com/my#campaigns\n\nEvery Network Weekend deal across the network: https://instantadpay.com/weekend', 'notice'); } catch (e) {}
|
|
}
|
|
}
|
|
if (inWeekend(ts) && cents >= cfg().starterMin && !S.bundles[ev.tx] && await claimOnce('pdb:' + ev.tx)) {
|
|
const c = cfg(); const builder = cents >= c.builderMin;
|
|
const wallet = builder ? await walletOf(ev) : '';
|
|
S.bundles[ev.tx] = { memberId: ev.buyerId, cents, at: ts, builder, wallet }; save();
|
|
out.starter = true; out.builder = builder;
|
|
const lines = ['Your ' + usdOf(cents) + ' package came in during Network Weekend, so it carries the Weekend Starter Bundle: a ' + '500-credit LinkSpin code, ' + c.lsCode + '. Enter it at https://linkspin.app (same email as here, one per account).'];
|
|
if (builder) lines.push('It is also a Builder Bundle: DownlineHydra Pro is on its way to the wallet that paid' + (wallet ? ' (' + wallet.slice(0, 6) + '...' + wallet.slice(-4) + ')' : '') + ', free, while the first ' + c.builderCap + ' comps last. If that wallet already holds Pro, nothing changes. It lands within the hour; check https://downlinehydra.com.');
|
|
lines.push(CREDITS_LINE);
|
|
try { await X.notify(ev.buyerId, 'Network Weekend: your bundle extras', lines.join('\n\n'), 'notice'); } catch (e) {}
|
|
}
|
|
return out;
|
|
}
|
|
// the buying position's wallet: the chain index first (MemberActivated), then a contract read
|
|
async function walletOf(ev) {
|
|
const id = Number(ev.buyerId) || 0; if (!id || !X.chain) return '';
|
|
try { for (const e of X.chain.recentEvents(1e9)) if (e.type === 'MemberActivated' && Number(e.id) === id && e.account) return String(e.account).toLowerCase(); } catch (e) {}
|
|
try { const m = await X.chain.member(id); return m && m.account ? String(m.account).toLowerCase() : ''; } catch (e) { return ''; }
|
|
}
|
|
// GET /api/network/weekend-builders (DownlineHydra pulls it): every $100+ package in the window, from the chain index, never a counter
|
|
async function builders() {
|
|
const c = cfg(); const out = [];
|
|
let evs = []; try { evs = X.chain.recentEvents(1e9); } catch (e) {}
|
|
for (const ev of evs) {
|
|
if (ev.type !== 'Purchase' || (Number(ev.priceCents) || 0) < c.builderMin) continue;
|
|
const ts = tsOf(ev); if (!(ts >= c.start && ts < c.end)) continue;
|
|
const wallet = (S.bundles[ev.tx] && S.bundles[ev.tx].wallet) || await walletOf(ev);
|
|
if (wallet) out.push({ wallet, txHash: ev.tx, usdCents: Number(ev.priceCents), at: new Date(ts).toISOString() });
|
|
}
|
|
return { start: new Date(c.start).toISOString(), end: new Date(c.end).toISOString(), cap: c.builderCap, builders: out.sort((a, b) => a.at < b.at ? -1 : 1) };
|
|
}
|
|
|
|
// the public view for the strip, Overview card and /weekend page
|
|
function view(t) {
|
|
const c = cfg(); t = t == null ? now() : t;
|
|
const d = dayAt(t); const live = inWeekend(t);
|
|
// nothing about the deals is published before Thanksgiving Thursday 00:00 CT (24 h before the start)
|
|
if (t < c.start - 86400000) return { on: c.on, live: false, today: null, days: [], startsAt: new Date(c.start).toISOString(), endsAt: new Date(c.end).toISOString(), published: false };
|
|
const list = Object.entries(c.days).sort().map(([k, v]) => ({ day: k, name: v.name, pct: Number(v.pct), minUsd: (Number(v.minCents) || 0) / 100 }));
|
|
let st = null;
|
|
if (d) { let packs = 0, usd = 0; try { for (const ev of X.chain.recentEvents(1e9)) if (ev.type === 'Purchase' && ev.priceCents >= d.minCents && dayOf(tsOf(ev)) === d.day) { packs++; usd += ev.priceCents / 100; } } catch (e) {}
|
|
st = { packs, usd, bonusCredits: Object.values(S.granted).filter(g => g.day === d.day).reduce((s, g) => s + g.bonus, 0) }; }
|
|
return { on: c.on, live, today: d ? { day: d.day, name: d.name, pct: d.pct, minUsd: d.minCents / 100, stats: st } : null, days: list,
|
|
startsAt: new Date(c.start).toISOString(), endsAt: new Date(c.end).toISOString(), passEndsAt: new Date(c.passEnd).toISOString(),
|
|
published: true, passBonusLive: c.on && c.tiersOn && t >= c.start && t < c.passEnd, passBonus: c.passBonus, lsCode: live ? c.lsCode : null, builderCap: c.builderCap, note: CREDITS_LINE };
|
|
}
|
|
|
|
// Thanksgiving: friday.js sends this instead of the normal Thursday copy when tomorrow is a mapped Friday (one message)
|
|
function thursdayCopy(nextFridayKey) {
|
|
const c = cfg(); const d = c.on && c.days[nextFridayKey]; if (!d) return null;
|
|
const B = c.mailBase;
|
|
return { subject: d.name + ' starts at midnight: Network Weekend',
|
|
text: 'Network Weekend starts tonight at midnight Central and runs Black Friday to Cyber Monday, midnight to midnight.\n\n'
|
|
+ 'On InstantAdPay:\n'
|
|
+ 'Black Friday (Fri 11-27): +40% bonus ad credits on any $5+ pack, and the same pack gives you a free 7-day Game Pass.\n'
|
|
+ 'Saturday and Sunday: +20% bonus ad credits on any $5+ pack.\n'
|
|
+ 'Cyber Monday (Mon 11-30): +30% bonus ad credits on any $20+ pack.\n'
|
|
+ 'Any $20+ pack also gets a 500-credit LinkSpin code. Any $100+ pack also gets DownlineHydra Pro free, while the first ' + c.builderCap + ' comps last.\n'
|
|
+ 'Code NETWORKWEEKEND: 300 bonus ad credits, one per account, from midnight.\n\n'
|
|
+ 'Every pack still pays its sponsor line in the same transaction, at the full price. ' + CREDITS_LINE + '\n\n'
|
|
+ 'Every network site has its own weekend deal: ' + B + '/weekend\n'
|
|
+ 'Line up your pack: ' + B + '/my#buy' };
|
|
}
|
|
// the chatbot (chatbot.js): a fact for the system prompt and one answer, only while the weekend (or the Game Pass days) is on
|
|
function chatFact(t) {
|
|
const c = cfg(); t = t == null ? now() : t;
|
|
if (!c.on || t < c.start - 86400000 || t >= (c.tiersOn ? c.passEnd : c.end)) return '';
|
|
if (t < c.start) return '- NETWORK WEEKEND (starts Fri 2026-11-27 00:00 Central, tomorrow): Black Friday to Cyber Monday, midnight to midnight Central. Not live yet: say it starts at midnight; deals at https://instantadpay.com/weekend.\n';
|
|
if (t >= c.end) return !c.tiersOn ? '' : '- NETWORK WEEKEND is over (it ended Mon 11-30 at midnight Central). Still on until Thu 12-03 23:59 Central: tier Game Pass bonus days (Explorer and Champion 45 days, Legend 365 + 60). Five Dollar Friday is back to +20% on $5+ from Fri 12-04.\n';
|
|
return '- NETWORK WEEKEND (LIVE now, Fri 11-27 00:00 to Mon 11-30 23:59 Central, midnight to midnight): Black Friday +40% bonus ad credits on any $5+ pack (instead of the usual Five Dollar Friday +20%, never both) plus the free 7-day Game Pass; Saturday and Sunday +20% on $5+; Cyber Monday +30% on $20+. Weekend Starter Bundle: any $20+ pack gets the LinkSpin code ' + c.lsCode + ' (500 LinkSpin credits, shown on the purchase notice). Builder Bundle: any $100+ pack gets DownlineHydra Pro free for the paying wallet, first ' + c.builderCap + ' comps, nobody is paid on a comp. Code NETWORKWEEKEND: 300 bonus ad credits, paid in 5 daily installments as the member finishes the daily ad set, one per account, new and existing accounts, valid until Mon 11-30 23:59 Central.' + (c.tiersOn ? ' Tier Game Pass bonus days through Thu 12-03 23:59 Central (Explorer and Champion 45 days, Legend 365 + 60).' : '') + ' Every pack pays its sponsor line in full. No price is cut on InstantAdPay. All deals: https://instantadpay.com/weekend. Ad credits buy advertising, not income; never promise income.\n';
|
|
}
|
|
const CHAT_RE = /(black friday|cyber monday|network weekend|weekend (deal|sale|bonus|promo|special)s?|thanksgiving|bundle|networkweekend|friday (bonus|promo|deal|special)|five dollar friday)/i;
|
|
function chatAnswer(msg, t) {
|
|
const c = cfg(); t = t == null ? now() : t;
|
|
if (!c.on || !CHAT_RE.test(String(msg || '')) || t < c.start - 86400000 || t >= c.end) return null;
|
|
if (t < c.start) return 'Network Weekend starts tonight at midnight Central and runs Black Friday to Cyber Monday, midnight to midnight. Black Friday: +40% bonus ad credits on any $5+ pack plus a free 7-day Game Pass. Saturday and Sunday: +20% on $5+. Cyber Monday: +30% on $20+. Any $20+ pack adds a 500-credit LinkSpin code, any $100+ pack adds DownlineHydra Pro while the first ' + c.builderCap + ' comps last, and code NETWORKWEEKEND gives 300 bonus ad credits from midnight. Every deal: https://instantadpay.com/weekend. ' + CREDITS_LINE;
|
|
const d = dayAt(t);
|
|
return 'Network Weekend is on now, midnight to midnight Central through Cyber Monday. ' + (d ? 'Today is ' + d.name + ': +' + d.pct + '% bonus ad credits on any ' + usdOf(d.minCents) + '+ pack' + (weekdayOf(t) === 'Fri' ? ' (this replaces the usual Five Dollar Friday +20%), plus a free 7-day Game Pass' : '') + '. ' : '')
|
|
+ 'Saturday and Sunday are +20% on $5+, Cyber Monday is +30% on $20+. Any $20+ pack also gets the LinkSpin code ' + c.lsCode + ' (500 LinkSpin credits) on your purchase notice, and any $100+ pack gets DownlineHydra Pro free for the paying wallet while the first ' + c.builderCap + ' comps last. Code NETWORKWEEKEND gives 300 bonus ad credits over 5 days of your daily ad set, one per account. Buy under My account > Buy packages: https://instantadpay.com/my#buy. Every deal on the network: https://instantadpay.com/weekend. ' + CREDITS_LINE;
|
|
}
|
|
|
|
module.exports = { init, cfg, dayAt, fridayPct, fridayName, inWeekend, weekendLive, passBonusDays, onEvent, builders, view, thursdayCopy, chatFact, chatAnswer, now, DEFAULT_DAYS, CREDITS_LINE };
|