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(resend): reach later pages of email and marketing collections
Rudy Celekli0346d4c34ca2
diff --git a/tests/clis/resend-list-cursors.test.cjs b/tests/clis/resend-list-cursors.test.cjsnew file mode 100644index 0000000..d23bb65--- /dev/null+++ b/tests/clis/resend-list-cursors.test.cjs@@ -0,0 +1,8 @@+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/resend.js')+const resources=['emails','domains','broadcasts','segments','templates','api-keys']+function run(args,network=true){const script=`global.fetch=async(url,options)=>{if(!${network})throw new Error('Unexpected network');return{status:200,text:async()=>JSON.stringify({url,method:options.method,has_more:false,data:[]})}};process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)})`;return spawnSync(process.execPath,['-e',script],{encoding:'utf8',timeout:5000,env:{RESEND_API_KEY:'fixture-key',PATH:process.env.PATH}})}+function result(r){assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)}+test('all supported collection commands can reach subsequent and previous pages',()=>{for(const resource of resources){for(const direction of ['after','before']){const r=result(run([resource,'list','--'+direction,'cursor/+id','--limit','100']));const u=new URL(r.url);assert.equal(u.searchParams.get(direction),'cursor/+id');assert.equal(u.searchParams.get('limit'),'100');assert.equal(r.method,'GET')}}})+test('default requests retain omitted pagination and preserve provider response',()=>{for(const resource of resources){const r=result(run([resource,'list']));assert.equal(new URL(r.url).search,'');assert.equal(r.has_more,false);assert.deepEqual(r.data,[])}})+test('ambiguous cursors and malformed limits are rejected before fetch',()=>{for(const resource of resources){for(const options of [['--after','a','--before','b'],['--after'],['--before',''],['--limit'],['--limit','0'],['--limit','101'],['--limit','1.5']]){const r=run([resource,'list',...options],false);assert.equal(r.status,1,resource+' '+options);assert.doesNotMatch(r.stderr,/Unexpected network/)}}})+test('dry runs show cursor encoding and redact authentication',()=>{const r=result(run(['emails','list','--after','cursor/+id','--dry-run'],false));assert.equal(new URL(r.url).searchParams.get('after'),'cursor/+id');assert.equal(JSON.stringify(r).includes('fixture-key'),false)})diff --git a/tools/clis/resend.js b/tools/clis/resend.jsindex 555677b..3c25556 100755--- a/tools/clis/resend.js+++ b/tools/clis/resend.js@@ -59,6 +59,23 @@ function booleanArg(name) {throw new Error(`--${name} must be true or false (or a bare flag for true)`)}+function listQuery() {+ const params = new URLSearchParams()+ if (args.after !== undefined && args.before !== undefined) throw new Error('--after and --before are mutually exclusive')+ for (const name of ['after', 'before']) {+ if (args[name] === undefined) continue+ if (typeof args[name] !== 'string' || !args[name].trim()) throw new Error(`--${name} requires a nonempty cursor`)+ params.set(name, args[name])+ }+ if (args.limit !== undefined) {+ if (typeof args.limit !== 'string' || !/^\d+$/.test(args.limit) || Number(args.limit) < 1 || Number(args.limit) > 100) {+ throw new Error('--limit must be an integer from 1 to 100')+ }+ params.set('limit', args.limit)+ }+ return params.toString()+}+async function main() {let result@@ -83,9 +100,8 @@ async function main() {case 'emails':switch (sub) {case 'list': {- const params = new URLSearchParams()- if (args.limit) params.set('limit', args.limit)- result = await api('GET', `/emails?${params}`)+ const qs = listQuery()+ result = await api('GET', `/emails${qs ? '?' + qs : ''}`)break}case 'get':@@ -102,9 +118,8 @@ async function main() {case 'domains':switch (sub) {case 'list': {- const params = new URLSearchParams()- if (args.limit) params.set('limit', args.limit)- result = await api('GET', `/domains?${params}`)+ const qs = listQuery()+ result = await api('GET', `/domains${qs ? '?' + qs : ''}`)break}case 'get':@@ -126,9 +141,11 @@ async function main() {case 'api-keys':switch (sub) {- case 'list':- result = await api('GET', '/api-keys')+ case 'list': {+ const qs = listQuery()+ result = await api('GET', `/api-keys${qs ? '?' + qs : ''}`)break+ }case 'create': {const body = { name: args.name }if (args.permission) body.permission = args.permission@@ -243,11 +260,8 @@ async function main() {case 'templates':switch (sub) {case 'list': {- const params = new URLSearchParams()- if (args.limit) params.set('limit', args.limit)- if (args.after) params.set('after', args.after)- if (args.before) params.set('before', args.before)- result = await api('GET', `/templates?${params}`)+ const qs = listQuery()+ result = await api('GET', `/templates${qs ? '?' + qs : ''}`)break}case 'get':@@ -298,9 +312,8 @@ async function main() {case 'broadcasts':switch (sub) {case 'list': {- const params = new URLSearchParams()- if (args.limit) params.set('limit', args.limit)- result = await api('GET', `/broadcasts?${params}`)+ const qs = listQuery()+ result = await api('GET', `/broadcasts${qs ? '?' + qs : ''}`)break}case 'get':@@ -332,9 +345,8 @@ async function main() {case 'segments':switch (sub) {case 'list': {- const params = new URLSearchParams()- if (args.limit) params.set('limit', args.limit)- result = await api('GET', `/segments?${params}`)+ const qs = listQuery()+ result = await api('GET', `/segments${qs ? '?' + qs : ''}`)break}case 'get':@@ -356,7 +368,7 @@ async function main() {error: 'Unknown command',usage: {send: 'send --from <email> --to <email> --subject <subject> --html <html>',- emails: 'emails [list|get|cancel] [id]',+ emails: 'emails [list|get|cancel] [id] [--limit <1-100>] [--after <cursor> | --before <cursor>]',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>]',diff --git a/tools/integrations/resend.md b/tools/integrations/resend.mdindex 5489c46..a47219b 100644--- a/tools/integrations/resend.md+++ b/tools/integrations/resend.md@@ -210,3 +210,13 @@ await resend.emails.send({- emails- onboarding++## Paging bundled CLI collections++The `emails list`, `domains list`, `broadcasts list`, `segments list`, `api-keys list` and `templates list` commands accept `--limit <1-100>` and either `--after <id>` or `--before <id>`. Inspect the provider's `has_more` and returned object IDs, then request the next page manually. The CLI preserves raw responses and does not silently aggregate or issue more calls.++```bash+node tools/clis/resend.js emails list --limit 100 --after <last_email_id> --dry-run+```++No flags retains provider defaults, including unpaginated legacy lists where the provider returns all items unless a limit is supplied. Supplying both directions, an empty cursor or an invalid limit fails before fetch. See [Resend pagination](https://resend.com/docs/api-reference/pagination); fixtures verify request construction without live account calls.