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(close): paginate CRM lists without skipping selected page sizes
Rudy Celeklic3b232d0f8d5
diff --git a/tests/clis/close-collection-pagination.test.cjs b/tests/clis/close-collection-pagination.test.cjsnew file mode 100644index 0000000..8f7be78--- /dev/null+++ b/tests/clis/close-collection-pagination.test.cjs@@ -0,0 +1,9 @@+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/close.js')+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:{CLOSE_API_KEY:'fixture-key',PATH:process.env.PATH}})}+function out(r){assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)}+const resources=['leads','contacts','opportunities','activities','tasks']+test('page offsets follow the selected page size across CRM collections',()=>{for(const resource of resources){const u=new URL(out(run([resource,'list','--page','2','--limit','25'])).url);assert.equal(u.searchParams.get('_skip'),'25',resource);assert.equal(u.searchParams.get('_limit'),'25')}})+test('explicit offsets and zero retain filters and provider responses',()=>{const r=out(run(['contacts','list','--skip','0','--limit','100','--lead-id','lead/+id']));const u=new URL(r.url);assert.equal(u.searchParams.get('_skip'),'0');assert.equal(u.searchParams.get('lead_id'),'lead/+id');assert.deepEqual(r.data,[]);assert.equal(r.has_more,false)})+test('omission and legacy page selection retain established semantics',()=>{assert.equal(new URL(out(run(['leads','list'])).url).search,'');const u=new URL(out(run(['leads','list','--page','2'])).url);assert.equal(u.searchParams.get('_skip'),'100');assert.equal(u.searchParams.get('_limit'),'100')})+test('malformed and ambiguous pagination fails before fetch',()=>{for(const flags of [['--page','0'],['--page','2junk'],['--page'],['--skip','-1'],['--limit','101'],['--limit','1.5'],['--page','2','--skip','25']]){const r=run(['contacts','list',...flags],false);assert.equal(r.status,1);assert.doesNotMatch(r.stderr,/Unexpected network/)}})+test('dry run is paginated and credential-redacted',()=>{const r=out(run(['tasks','list','--page','3','--limit','10','--dry-run'],false));assert.equal(new URL(r.url).searchParams.get('_skip'),'20');assert.equal(JSON.stringify(r).includes('fixture-key'),false)})diff --git a/tools/clis/close.js b/tools/clis/close.jsindex aef2d84..fd8aa85 100755--- a/tools/clis/close.js+++ b/tools/clis/close.js@@ -54,6 +54,25 @@ function parseArgs(args) {const args = parseArgs(rawArgs)const [cmd, sub, ...rest] = args._+function addPagination(params) {+ const integer = (name, fallback, minimum) => {+ const raw = args[name]+ if (raw === undefined) return fallback+ if (typeof raw !== 'string' || !/^\d+$/.test(raw) || !Number.isSafeInteger(Number(raw)) || Number(raw) < minimum) {+ throw new Error(`--${name} requires an integer of at least ${minimum}`)+ }+ return Number(raw)+ }+ if (args.page !== undefined && args.skip !== undefined) throw new Error('--page and --skip are mutually exclusive')+ const limit = integer('limit', 100, 1)+ if (limit > 100) throw new Error('--limit must be at most 100')+ const page = integer('page', 1, 1)+ const skip = integer('skip', (page - 1) * limit, 0)+ if (!Number.isSafeInteger(skip)) throw new Error('Pagination offset is too large')+ if (args.limit !== undefined || args.page !== undefined) params.set('_limit', String(limit))+ if (args.page !== undefined || args.skip !== undefined) params.set('_skip', String(skip))+}+async function main() {let result@@ -63,7 +82,7 @@ async function main() {case 'list': {const params = new URLSearchParams()if (args.query) params.set('query', args.query)- if (args.page) params.set('_skip', (parseInt(args.page) - 1) * 100)+ addPagination(params)const qs = params.toString()result = await api('GET', `/lead/${qs ? '?' + qs : ''}`)break@@ -93,6 +112,7 @@ async function main() {case 'list': {const params = new URLSearchParams()if (args['lead-id']) params.set('lead_id', args['lead-id'])+ addPagination(params)const qs = params.toString()result = await api('GET', `/contact/${qs ? '?' + qs : ''}`)break@@ -128,6 +148,7 @@ async function main() {case 'list': {const params = new URLSearchParams()if (args.status) params.set('status', args.status)+ addPagination(params)const qs = params.toString()result = await api('GET', `/opportunity/${qs ? '?' + qs : ''}`)break@@ -159,6 +180,7 @@ async function main() {const params = new URLSearchParams()if (args['lead-id']) params.set('lead_id', args['lead-id'])if (args.type) params.set('_type__type', args.type)+ addPagination(params)const qs = params.toString()result = await api('GET', `/activity/${qs ? '?' + qs : ''}`)break@@ -174,6 +196,7 @@ async function main() {const params = new URLSearchParams()if (args['assigned-to']) params.set('assigned_to', args['assigned-to'])if (args['is-complete']) params.set('is_complete', args['is-complete'])+ addPagination(params)const qs = params.toString()result = await api('GET', `/task/${qs ? '?' + qs : ''}`)break@@ -199,7 +222,7 @@ async function main() {error: 'Unknown command',usage: {leads: {- list: 'leads list [--query <q>] [--page <n>]',+ list: 'leads list [--query <q>] [--page <n> | --skip <n>] [--limit <1-100>]',get: 'leads get --id <id>',create: 'leads create --name <name> [--url <url>] [--description <desc>]',},diff --git a/tools/integrations/close.md b/tools/integrations/close.mdindex b32c386..b8960de 100644--- a/tools/integrations/close.md+++ b/tools/integrations/close.md@@ -189,3 +189,13 @@ POST https://api.close.com/api/v1/task/- revops- sales-enablement- cold-email++## Paging bundled CLI CRM collections++All five list commands (`leads`, `contacts`, `opportunities`, `activities`, `tasks`) accept `--page <positive_integer>` or `--skip <nonnegative_offset>` and optional `--limit <1-100>`. Page offsets use the selected limit, so page 2 at limit 25 starts at offset 25, not 100. Omitted flags preserve provider defaults; legacy `--page` without a limit uses 100 records per page.++```bash+node tools/clis/close.js contacts list --lead-id lead_example --page 2 --limit 25 --dry-run+```++Read `has_more` and request subsequent pages manually; the CLI preserves raw responses and never fetches extra pages silently. The CLI conservatively supports limits up to 100; provider resource-specific limits still apply. [Close pagination](https://developer.close.com/api/overview/pagination) documents `_skip` and `_limit`. Contract tests use fixtures, not real CRM records.