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
feat(brevo): support explicit contact channel suppression
Rudy Celekli0be08edc93ca
diff --git a/tests/clis/brevo-contact-suppression.test.cjs b/tests/clis/brevo-contact-suppression.test.cjsnew file mode 100644index 0000000..ebf08e5--- /dev/null+++ b/tests/clis/brevo-contact-suppression.test.cjs@@ -0,0 +1,38 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/brevo.js')+function run(args, oracle='') {+ const code=`global.fetch=async(url,options)=>{const assert=require('node:assert/strict');${oracle};return new Response(JSON.stringify({id:21}),{status:200})};process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath,['-e',code],{encoding:'utf8',timeout:10000,env:{...process.env,BREVO_API_KEY:'fixture-token'}})+}+function output(r){assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)}+for(const operation of ['create','update']) {+ const args=['contacts',operation,'--email','[email protected]']+ const resource=operation==='create'?'/contacts':'/contacts/owned%2Btest%40example.com'+ const legacy=operation==='create'?{email:'[email protected]'}:{}+ for(const [flag,field] of [['email-blacklisted','emailBlacklisted'],['sms-blacklisted','smsBlacklisted']]) {+ for(const value of [true,false]) test(`${operation} preserves ${field} literal ${value}`,()=>{+ output(run([...args,'--'+flag,String(value)],`assert.equal(url,${JSON.stringify('https://api.brevo.com/v3'+resource)});assert.equal(options.method,${JSON.stringify(operation==='create'?'POST':'PUT')});assert.equal(options.headers['api-key'],'fixture-token');assert.deepEqual(JSON.parse(options.body),${JSON.stringify({...legacy,[field]:value})})`))+ })+ for(const bad of [[],['yes'],['FALSE']]) test(`${operation} rejects ${flag} ${bad.join(' ')||'without a value'} before transport`,()=>{+ const result=run([...args,'--'+flag,...bad],"throw new Error('unexpected fetch')")+ assert.notEqual(result.status,0);assert.match(result.stderr,/must be true or false/);assert.doesNotMatch(result.stderr,/unexpected fetch/)+ })+ }+ test(`${operation} combines independent channels and preserves existing attributes and lists`,()=>{+ output(run([...args,'--first-name','Owned','--list-ids','2,3','--email-blacklisted','true','--sms-blacklisted','false'],`assert.deepEqual(JSON.parse(options.body),${JSON.stringify({...legacy,attributes:{FIRSTNAME:'Owned'},listIds:[2,3],emailBlacklisted:true,smsBlacklisted:false})})`))+ })+ test(`${operation} omits unsupplied suppression fields`,()=>{+ output(run(args,`assert.deepEqual(JSON.parse(options.body),${JSON.stringify(legacy)})`))+ })+ test(`${operation} previews explicit false offline with masked credentials`,()=>{+ const preview=output(run([...args,'--email-blacklisted','false','--sms-blacklisted','true','--dry-run'],"throw new Error('unexpected fetch')"))+ assert.deepEqual(preview.body,{...legacy,emailBlacklisted:false,smsBlacklisted:true});assert.equal(preview.headers['api-key'],'***')+ })+}+test('contact read preserves returned suppression flags',()=>{+ const result=output(run(['contacts','get','--email','[email protected]'],"assert.equal(url,'https://api.brevo.com/v3/contacts/owned%40example.com');return new Response(JSON.stringify({id:21,emailBlacklisted:true,smsBlacklisted:false}),{status:200})"))+ assert.deepEqual(result,{id:21,emailBlacklisted:true,smsBlacklisted:false})+})diff --git a/tools/clis/brevo.js b/tools/clis/brevo.jsindex 62722c1..3edc46d 100755--- a/tools/clis/brevo.js+++ b/tools/clis/brevo.js@@ -53,6 +53,15 @@ function parseArgs(args) {const args = parseArgs(rawArgs)const [cmd, sub, ...rest] = args._+function contactSuppression(body) {+ for (const [flag, field] of [['email-blacklisted', 'emailBlacklisted'], ['sms-blacklisted', 'smsBlacklisted']]) {+ if (args[flag] === undefined) continue+ if (args[flag] !== 'true' && args[flag] !== 'false') throw new Error(`--${flag} must be true or false`)+ body[field] = args[flag] === 'true'+ }+ return body+}+async function main() {let resultconst limit = args.limit ? Number(args.limit) : 50@@ -95,7 +104,7 @@ async function main() {if (args['last-name']) body.attributes.LASTNAME = args['last-name']}if (args['list-ids']) body.listIds = args['list-ids'].split(',').map(Number)- result = await api('POST', '/contacts', body)+ result = await api('POST', '/contacts', contactSuppression(body))break}case 'update': {@@ -109,7 +118,7 @@ async function main() {}if (args['list-ids']) body.listIds = args['list-ids'].split(',').map(Number)if (args['unlink-list-ids']) body.unlinkListIds = args['unlink-list-ids'].split(',').map(Number)- result = await api('PUT', `/contacts/${encodeURIComponent(id)}`, body)+ result = await api('PUT', `/contacts/${encodeURIComponent(id)}`, contactSuppression(body))break}case 'delete': {@@ -355,7 +364,7 @@ async function main() {campaigns: 'campaigns [list | get --id <id> | create --name <name> | send-now --id <id> | send-test --id <id> --emails <e1,e2>]',sms: 'sms [send --from <name> --to <phone> --content <msg> | campaigns]',senders: 'senders [list | create --name <name> --email <email>]',- options: '--limit <n> --offset <n> --status <status>',+ options: '--limit <n> --offset <n> --status <status>; contacts create/update: --email-blacklisted <true|false> --sms-blacklisted <true|false>',}}}diff --git a/tools/integrations/brevo.md b/tools/integrations/brevo.mdindex 9187cf6..c772615 100644--- a/tools/integrations/brevo.md+++ b/tools/integrations/brevo.md@@ -266,3 +266,31 @@ Brevo uses standard REST with offset-based pagination (`limit` and `offset` para- transactional-email- lifecycle-marketing- contact-management++## Contact channel suppression with the CLI++Contact creation and updates accept `--email-blacklisted true|false` and+`--sms-blacklisted true|false`. The literal values become JSON booleans; omitted+flags leave the existing request unchanged. Bare flags and other values are+rejected before transport. These options change contact channel suppression;+they do not send messages, delete the contact, or change list membership.++```bash+node tools/clis/brevo.js contacts get --email [email protected]+node tools/clis/brevo.js contacts update --email [email protected] --email-blacklisted true --dry-run+node tools/clis/brevo.js contacts create --email [email protected] --email-blacklisted true --sms-blacklisted true --dry-run+```++Read the current contact and the user's requested channel preference before+changing an existing record. Use `true` to carry an opt-out into the documented+channel flag. Setting a flag to `false` allows that channel again: only restore+it when the user has authorized that change and there is appropriate permission+to contact the person. List membership alone is not evidence of consent.+Unrelated name or list updates should omit these flags rather than defaulting+them to `false`. The CLI does not establish consent or guarantee compliance with+communication rules. Brevo's separate transactional-email sender blocklist is+not managed by these options.++See the current [create-contact](https://developers.brevo.com/reference/create-contact)+and [update-contact](https://developers.brevo.com/reference/update-contact)+request schemas for `emailBlacklisted` and `smsBlacklisted`.