Refill notices: Wired Wednesday in the bonus ladder + deploy-overlap claims (Fuel Your Offers stage 1, Marty approved 2026-10-24). The bonus block now lists Five Dollar Friday AND Wired Wednesday (from their live settings: wednesdayPromo, wednesdayBonusPct 25, wednesdayMinCents 2000, Central time), and takes the member's refuel-streak line from a streakLine(owner) hook (filled in stage 2). Every send is claimed in event_marks first, so the two app copies of a deploy never both email a person. qa/refill.test.cjs (copy, settings, hook, two copies) + run.sh fuel mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,10 @@
|
||||
//
|
||||
// Settings (siteConfig): refillNotices '1'|'0' (default on), refillLowPct (80) the share of budget
|
||||
// delivered that counts as "running low".
|
||||
//
|
||||
// 2026-10-24 (Fuel Your Offers): the bonus block names Wired Wednesday next to Five Dollar Friday, and takes
|
||||
// the member's refuel-streak line from X.streakLine(owner) -> { text, html } | null when the streak is on.
|
||||
// Every send is claimed first (marks.js), so the two app copies of a deploy never both write to a person.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
@@ -32,6 +36,9 @@ function cfg() {
|
||||
lowPct: Math.min(99, Math.max(50, Number(c.refillLowPct) || 80)),
|
||||
fridayOn: String(c.fridayPromo == null ? '1' : c.fridayPromo) === '1',
|
||||
fridayPct: Number(c.fridayBonusPct) || 20,
|
||||
wedOn: String(c.wednesdayPromo == null ? '1' : c.wednesdayPromo) === '1',
|
||||
wedPct: Math.max(0, Number(c.wednesdayBonusPct) || 25),
|
||||
wedMinUsd: Math.max(0, Number(c.wednesdayMinCents) || 2000) / 100,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,21 +68,34 @@ const PACKS = [
|
||||
{ price: 500, credits: 70000, bonus: 40 },
|
||||
];
|
||||
|
||||
function ladderText() {
|
||||
// the day bonuses, one line each; Friday and Wednesday never fall on the same day
|
||||
function dayBonusLines() {
|
||||
const c = cfg(); const out = [];
|
||||
if (c.fridayOn) out.push({ title: 'Five Dollar Friday', body: 'any package from $5 up, bought on a Friday (Central time), earns an extra ' + c.fridayPct + '% in credits on top of the above.' });
|
||||
if (c.wedOn) out.push({ title: 'Wired Wednesday', body: 'any package from $' + c.wedMinUsd + ' up, bought on a Wednesday (Central time), earns an extra ' + c.wedPct + '% in credits, wired in the moment it settles.' });
|
||||
return out;
|
||||
}
|
||||
async function streakLine(owner) {
|
||||
if (typeof X.streakLine !== 'function' || !owner) return null;
|
||||
try { return await X.streakLine(owner); } catch (e) { return null; }
|
||||
}
|
||||
function ladderText(sl) {
|
||||
const c = cfg();
|
||||
const rows = PACKS.map(p => ' $' + p.price + ' -> ' + money(p.credits) + ' credits' + (p.bonus ? ' (' + p.bonus + '% more per dollar)' : ''));
|
||||
let s = 'Ad packages, and what each one adds to your balance:\n\n' + rows.join('\n')
|
||||
+ '\n\nA credit is one cent of delivery, so the bigger packages are simply more delivery for the same dollar.';
|
||||
if (c.fridayOn) s += '\n\nFive Dollar Friday: any package from $5 up, bought on a Friday, earns an extra ' + c.fridayPct + '% in credits on top of the above.';
|
||||
for (const d of dayBonusLines()) s += '\n\n' + d.title + ': ' + d.body;
|
||||
if (sl && sl.text) s += '\n\n' + sl.text;
|
||||
return s;
|
||||
}
|
||||
function ladderHtml() {
|
||||
function ladderHtml(sl) {
|
||||
const c = cfg();
|
||||
const rows = PACKS.map(p => '<tr><td style="padding:6px 14px 6px 0"><b>$' + p.price + '</b></td><td style="padding:6px 14px 6px 0">' + money(p.credits)
|
||||
+ ' credits</td><td style="padding:6px 0;color:#0E8F72">' + (p.bonus ? p.bonus + '% more per dollar' : '') + '</td></tr>').join('');
|
||||
return '<p><b>Ad packages, and what each one adds to your balance:</b></p><table style="border-collapse:collapse">' + rows + '</table>'
|
||||
+ '<p style="color:#556">A credit is one cent of delivery, so the bigger packages are simply more delivery for the same dollar.</p>'
|
||||
+ (c.fridayOn ? '<p><b>Five Dollar Friday:</b> any package from $5 up, bought on a Friday, earns an extra ' + c.fridayPct + '% in credits on top of the above.</p>' : '');
|
||||
+ dayBonusLines().map(d => '<p><b>' + d.title + ':</b> ' + esc(d.body) + '</p>').join('')
|
||||
+ (sl && sl.html ? '<p>' + sl.html + '</p>' : '');
|
||||
}
|
||||
|
||||
// what one owner's batch of campaigns says in the body
|
||||
@@ -112,7 +132,8 @@ async function compose(owner, list, state, credits) {
|
||||
: canRelaunch
|
||||
? 'You still have ' + money(Math.round(credits)) + ' credits in your balance, which is enough to put an ad back up right now without buying anything. Open Campaigns and start one: ' + SITE + '/my#campaigns'
|
||||
: 'Your balance is down to ' + money(Math.round(credits)) + ' credits, so the next campaign needs a top-up first: ' + SITE + '/my#buy';
|
||||
const lines = [opener, totals, next, ladderText(),
|
||||
const sl = await streakLine(owner);
|
||||
const lines = [opener, totals, next, ladderText(sl),
|
||||
'Every package pays your sponsor line in the same on-chain transaction, and every payout is on the public ledger at ' + SITE + '/ledger.'];
|
||||
const text = lines.filter(Boolean).join('\n\n') + '\n\nWhat each one did:\n' + describe(list) + '\n\nInstantAdPay';
|
||||
const html = '<p>' + opener + '</p>' + (totals ? '<p>' + totals + '</p>' : '')
|
||||
@@ -120,7 +141,7 @@ async function compose(owner, list, state, credits) {
|
||||
+ '<p><b>What each one did:</b></p><ul>' + list.map(c => '<li>' + esc(c.name || ('campaign #' + c.id)) + ' (' + esc(c.type || 'ad') + '): '
|
||||
+ money(Math.round(delivered(c))) + ' of ' + money(Math.round(n0(c.budget))) + ' credits delivered'
|
||||
+ (n0(c.imps) ? ', ' + money(n0(c.imps)) + ' ' + unit(c) : '') + (n0(c.clicks) ? ', ' + money(n0(c.clicks)) + ' clicks' : '') + esc(videoNote(c)) + '</li>').join('') + '</ul>'
|
||||
+ ladderHtml()
|
||||
+ ladderHtml(sl)
|
||||
+ '<p style="color:#556">Every package pays your sponsor line in the same on-chain transaction, and every payout is on the public ledger.</p>';
|
||||
return { subject, text, html };
|
||||
}
|
||||
@@ -178,7 +199,7 @@ async function followUps(all, alreadySent) {
|
||||
if (credits < IDLE_MIN_CREDITS) { r.followUp = 'nocredits'; continue; }
|
||||
const list = r.campaigns.map(x => all.find(c => c.id === x.id) || x);
|
||||
const ok = await notify(r.owner, list, 'idle', r.id).catch(e => { console.error('refill follow-up', r.owner, e.message); return false; });
|
||||
r.followUp = ok ? S.seq : 'failed';
|
||||
r.followUp = ok ? S.seq : 'claimed';
|
||||
if (ok) sent++;
|
||||
}
|
||||
if (due.length) save();
|
||||
@@ -186,6 +207,9 @@ async function followUps(all, alreadySent) {
|
||||
}
|
||||
|
||||
async function notify(owner, list, state, parentId) {
|
||||
// claim before anything goes out: one copy of the app per message, ever (deploy overlap)
|
||||
const claimKey = 'refill:' + (state === 'idle' ? 'idle:' + parentId : list.map(c => c.id).sort((a, b) => a - b).join(',') + ':' + state);
|
||||
if (X.marks && !(await X.marks.claim(claimKey))) { if (state !== 'idle') for (const cm of list) S.sent[key(cm.id, state)] = S.sent[key(cm.id, state)] || -1; return false; }
|
||||
const acct = await X.accounts.byEmail(owner); if (!acct) return false;
|
||||
const stopped = X.drip && X.drip.isUnsubscribed ? await X.drip.isUnsubscribed(owner).catch(() => false) : false;
|
||||
let credits = 0; try { credits = await X.creditsFor(owner); } catch (e) {}
|
||||
@@ -281,4 +305,4 @@ function resetConversions(kinds) {
|
||||
return { cleared: n };
|
||||
}
|
||||
|
||||
module.exports = { init, tick, stats, resetConversions, PACKS };
|
||||
module.exports = { init, tick, stats, resetConversions, PACKS, compose };
|
||||
|
||||
Reference in New Issue
Block a user