Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(email): preserve explicit subscription and tracking booleans
Rudy Celekli0c68e0f5a4a8
diff --git a/tests/email-boolean-states.test.cjs b/tests/email-boolean-states.test.cjsnew file mode 100644index 0000000..0dc8d0b--- /dev/null+++ b/tests/email-boolean-states.test.cjs@@ -0,0 +1,42 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+function run(vendor, args, fetch = true) {+ const cli = path.resolve(__dirname, `../tools/clis/${vendor}.js`)+ const source = `global.fetch = async (url, options) => {+ if (!${fetch}) throw new Error('Unexpected network request');+ return { status: 200, text: async () => JSON.stringify({ url, method: options.method, body: options.body ? JSON.parse(options.body) : null }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000, env: {+ ...process.env, REWARDFUL_API_KEY: 'fake-key', RESEND_API_KEY: 'fake-key', POSTMARK_API_KEY: 'fake-key', BEEHIIV_API_KEY: 'fake-key', KLAVIYO_API_KEY: 'fake-key',+ } })+}+function output(result) { assert.equal(result.status, 0, result.stderr); return JSON.parse(result.stdout) }++const cases = [+ { vendor: 'resend', args: ['contacts', 'audience123', 'create', '--email', '[email protected]'], flag: 'unsubscribed', field: 'unsubscribed' },+ { vendor: 'resend', args: ['contacts', 'audience123', 'update', 'contact123'], flag: 'unsubscribed', field: 'unsubscribed' },+ { vendor: 'beehiiv', args: ['subscriptions', 'create', '--publication', 'pub_123', '--email', '[email protected]'], flag: 'reactivate-existing', field: 'reactivate_existing' },+ { vendor: 'beehiiv', args: ['subscriptions', 'create', '--publication', 'pub_123', '--email', '[email protected]'], flag: 'send-welcome-email', field: 'send_welcome_email' },+ { vendor: 'postmark', args: ['email', 'send', '--from', '[email protected]', '--to', '[email protected]', '--subject', 'Hello', '--text', 'World'], flag: 'track-opens', field: 'TrackOpens' },+]+for (const c of cases) {+ test(`${c.vendor} ${c.field}: false stays false, true and bare flag enable it`, () => {+ for (const [value, expected] of [['false', false], ['true', true], [undefined, true]]) {+ const argv = [...c.args, `--${c.flag}`]; if (value !== undefined) argv.push(value)+ assert.equal(output(run(c.vendor, argv)).body[c.field], expected)+ }+ })+ test(`${c.vendor} ${c.field}: invalid state cannot reach fetch`, () => {+ const result = run(c.vendor, [...c.args, `--${c.flag}`, 'maybe'], false)+ assert.equal(result.status, 1)+ assert.match(result.stderr, /must be true or false/)+ })+ test(`${c.vendor} ${c.field}: omitted state remains unset, dry run redacts auth`, () => {+ assert.equal(Object.hasOwn(output(run(c.vendor, c.args)).body, c.field), false)+ const preview = output(run(c.vendor, [...c.args, `--${c.flag}`, 'false', '--dry-run'], false))+ assert.equal(preview.body[c.field], false)+ assert.equal(JSON.stringify(preview).includes('fake-key'), false)+ })+}diff --git a/tools/clis/beehiiv.js b/tools/clis/beehiiv.jsindex 31ea085..1a71d59 100755--- a/tools/clis/beehiiv.js+++ b/tools/clis/beehiiv.js@@ -52,6 +52,13 @@ function parseArgs(args) {const args = parseArgs(process.argv.slice(2))const [cmd, sub, ...rest] = args._+function booleanArg(name) {+ const value = args[name]+ if (value === true || value === 'true') return true+ if (value === 'false') return false+ throw new Error(`--${name} must be true or false (or a bare flag for true)`)+}+async function main() {let resultconst pubId = args.publication || args.pub@@ -99,8 +106,8 @@ async function main() {const email = args.emailif (!email) { result = { error: '--email required' }; break }const body = { email }- if (args['reactivate-existing']) body.reactivate_existing = true- if (args['send-welcome-email']) body.send_welcome_email = true+ if (args['reactivate-existing'] !== undefined) body.reactivate_existing = booleanArg('reactivate-existing')+ if (args['send-welcome-email'] !== undefined) body.send_welcome_email = booleanArg('send-welcome-email')if (args['utm-source']) body.utm_source = args['utm-source']if (args['utm-medium']) body.utm_medium = args['utm-medium']if (args['utm-campaign']) body.utm_campaign = args['utm-campaign']diff --git a/tools/clis/postmark.js b/tools/clis/postmark.jsindex e66ca08..e9c7985 100755--- a/tools/clis/postmark.js+++ b/tools/clis/postmark.js@@ -63,6 +63,13 @@ function parseArgs(args) {const args = parseArgs(process.argv.slice(2))const [cmd, sub, ...rest] = args._+function booleanArg(name) {+ const value = args[name]+ if (value === true || value === 'true') return true+ if (value === 'false') return false+ throw new Error(`--${name} must be true or false (or a bare flag for true)`)+}+async function main() {let result@@ -86,7 +93,7 @@ async function main() {if (!args.html && !args.text) body.TextBody = ''if (args.tag) body.Tag = args.tagif (args.stream) body.MessageStream = args.stream- if (args['track-opens']) body.TrackOpens = true+ if (args['track-opens'] !== undefined) body.TrackOpens = booleanArg('track-opens')if (args['track-links']) body.TrackLinks = args['track-links']if (args.cc) body.Cc = args.ccif (args.bcc) body.Bcc = args.bcc@@ -361,7 +368,7 @@ async function main() {stats: 'stats [overview | sends | bounces | opens | clicks | spam]',server: 'server [get]',suppressions: 'suppressions [list | create --email <email> | delete --email <email>]',- options: '--tag <tag> --from <date> --to <date> --stream <stream-id>',+ options: '--tag <tag> --from <date> --to <date> --stream <stream-id> --track-opens [true|false]',}}}diff --git a/tools/clis/resend.js b/tools/clis/resend.jsindex 20c4851..5815b2a 100755--- a/tools/clis/resend.js+++ b/tools/clis/resend.js@@ -51,6 +51,13 @@ function parseArgs(args) {const args = parseArgs(process.argv.slice(2))const [cmd, sub, ...rest] = args._+function booleanArg(name) {+ const value = args[name]+ if (value === true || value === 'true') return true+ if (value === 'false') return false+ throw new Error(`--${name} must be true or false (or a bare flag for true)`)+}+async function main() {let result@@ -175,7 +182,7 @@ async function main() {const body = { email: args.email }if (args['first-name']) body.first_name = args['first-name']if (args['last-name']) body.last_name = args['last-name']- if (args.unsubscribed) body.unsubscribed = args.unsubscribed === 'true'+ if (args.unsubscribed !== undefined) body.unsubscribed = booleanArg('unsubscribed')result = await api('POST', `/audiences/${audienceId}/contacts`, body)break}@@ -184,7 +191,7 @@ async function main() {const body = {}if (args['first-name']) body.first_name = args['first-name']if (args['last-name']) body.last_name = args['last-name']- if (args.unsubscribed !== undefined) body.unsubscribed = args.unsubscribed === 'true'+ if (args.unsubscribed !== undefined) body.unsubscribed = booleanArg('unsubscribed')result = await api('PATCH', `/audiences/${audienceId}/contacts/${contactId}`, body)break}@@ -351,7 +358,7 @@ async function main() {domains: 'domains [list|get|create|verify|delete] [id] [--name <name>]','api-keys': 'api-keys [list|create|delete] [id] [--name <name>]',audiences: 'audiences [list|get|create|delete] [id] [--name <name>]',- contacts: 'contacts <audience_id> [list|get|create|update|delete] [contact_id] [--email <email>]',+ contacts: 'contacts <audience_id> [list|get|create|update|delete] [contact_id] [--email <email>] [--unsubscribed [true|false]]',webhooks: 'webhooks [list|get|create|delete] [id] [--endpoint <url>]',batch: 'batch --emails <json_array>',templates: 'templates [list|get|create|update|delete|publish|duplicate] [id] [--name <name>] [--html <html>] [--variables <json>]',