← back to Designer Wallcoverings
mailers/cc-api/build-houses-we-represent-campaign.js
52 lines
#!/usr/bin/env node
/**
* Build the "Houses We Represent" DRAFT campaign in Constant Contact.
* Uses the working cc-client (its own .env creds + rotated token cache).
* HTML source lives in the dedicated mailer project (already verified:
* 6 vendor rows, 23 product links all 200, Outlook-safe images).
*
* node build-houses-we-represent-campaign.js # dry-run (default)
* CC_LIVE=1 node build-houses-we-represent-campaign.js --confirm # create DRAFT
*
* Creates a DRAFT only — never schedules/sends (that stays Steve's click).
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const cc = require('./cc-client');
const CONFIRM = process.argv.includes('--confirm');
const MAILER = path.join(os.homedir(), 'Projects/dw-vendor-mailer/mailer.html');
const CAMPAIGN = {
name: `The Houses We Represent — ${new Date().toISOString().slice(0, 16).replace('T', ' ')}`,
subject: 'New: The Houses We Represent — order any as a $4.25 sample',
preheader: 'Six ateliers we represent — a few new arrivals from each, $4.25 samples.',
fromName: 'Designer Wallcoverings',
fromEmail: 'steve@designerwallcoverings.com',
replyTo: 'info@designerwallcoverings.com',
physicalAddress: {
address_line1: '15442 Ventura Bl',
city: 'Sherman Oaks',
state_code: 'CA',
postal_code: '91403',
country_code: 'US',
},
};
(async () => {
const html = fs.readFileSync(MAILER, 'utf8');
console.log(`mailer: ${MAILER} (${html.length} bytes)`);
console.log(`mode: ${CONFIRM ? '--confirm' : '--dry-run'} CC_LIVE=${process.env.CC_LIVE === '1' ? '1' : '(unset)'}`);
console.log(`subject: ${CAMPAIGN.subject}`);
const activityId = await cc.createCustomCodeCampaign({
name: CAMPAIGN.name, subject: CAMPAIGN.subject, preheader: CAMPAIGN.preheader,
fromEmail: CAMPAIGN.fromEmail, fromName: CAMPAIGN.fromName, replyTo: CAMPAIGN.replyTo,
htmlContent: html, physicalAddress: CAMPAIGN.physicalAddress, confirm: CONFIRM,
});
if (activityId && !activityId.__mock) {
console.log('\n✓ DRAFT created — campaign_activity_id:', activityId);
console.log(' Review + send from the Constant Contact dashboard (send stays manual).');
}
})().catch((e) => { console.error('ERROR:', e.message); process.exit(1); });