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(lemlist): preserve webhook event subscription filters
Rudy Celekli2df02bfa13ed
diff --git a/tests/clis/lemlist-webhook-type.test.cjs b/tests/clis/lemlist-webhook-type.test.cjsnew file mode 100644index 0000000..d587550--- /dev/null+++ b/tests/clis/lemlist-webhook-type.test.cjs@@ -0,0 +1,37 @@+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/lemlist.js')+function run(args, network = false) {+ const code = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected request');+ const body = options.body ? JSON.parse(options.body) : null;+ return {status: 200, text: async () => JSON.stringify({url, method: options.method, body, subscribedType: body?.type || 'all'})};+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const r = spawnSync(process.execPath, ['-e', code], {encoding: 'utf8', timeout: 5000, env: {...process.env, LEMLIST_API_KEY: 'test-only-key'}})+ assert.equal(r.status, 0, r.stderr)+ return JSON.parse(r.stdout)+}+test('documented webhook command sends the requested event as the API type', () => {+ const result = run(['hooks', 'create', '--target-url', 'https://example.com/hook', '--event', 'emailsOpened'], true)+ assert.equal(result.url, 'https://api.lemlist.com/api/hooks')+ assert.equal(result.method, 'POST')+ assert.deepEqual(result.body, {targetUrl: 'https://example.com/hook', type: 'emailsOpened'})+ assert.equal(result.subscribedType, 'emailsOpened')+})+test('webhook preview shows the same event filter without making a request', () => {+ const result = run(['hooks', 'create', '--target-url', 'https://example.com/hook', '--event', 'emailsReplied', '--dry-run'])+ assert.deepEqual(result.body, {targetUrl: 'https://example.com/hook', type: 'emailsReplied'})+ assert.equal(result.headers.Authorization, '***')+})+test('incomplete webhook creation still stops before a request', () => {+ assert.match(run(['hooks', 'create', '--target-url', 'https://example.com/hook']).error, /event required/)+ assert.match(run(['hooks', 'create', '--event', 'emailsOpened']).error, /target-url required/)+})+test('existing webhook list and delete methods are unchanged', () => {+ assert.equal(run(['hooks', 'list'], true).method, 'GET')+ const result = run(['hooks', 'delete', '--id', 'hook123'], true)+ assert.equal(result.method, 'DELETE')+ assert.equal(result.url, 'https://api.lemlist.com/api/hooks/hook123')+})diff --git a/tools/clis/lemlist.js b/tools/clis/lemlist.jsindex 3537581..22688a2 100755--- a/tools/clis/lemlist.js+++ b/tools/clis/lemlist.js@@ -185,7 +185,7 @@ async function main() {case 'create': {if (!args['target-url']) { result = { error: '--target-url required' }; break }if (!args.event) { result = { error: '--event required' }; break }- result = await api('POST', '/hooks', { targetUrl: args['target-url'], event: args.event })+ result = await api('POST', '/hooks', { targetUrl: args['target-url'], type: args.event })break}case 'delete': {diff --git a/tools/integrations/lemlist.md b/tools/integrations/lemlist.mdindex 3ee6607..4a25c2b 100644--- a/tools/integrations/lemlist.md+++ b/tools/integrations/lemlist.md@@ -91,6 +91,10 @@ node tools/clis/lemlist.js hooks create --target-url https://example.com/webhooknode tools/clis/lemlist.js hooks delete --id hook_123```+`--event` maps to the API's `type` filter. Sending a different field would omit+the filter and subscribe the destination to all events. See the+[Add Webhook reference](https://developer.lemlist.com/api-reference/endpoints/webhooks/add-webhook).+### Team info```bash