diff --git a/src/commands/broadcasts/list.ts b/src/commands/broadcasts/list.ts index a823b0c..a92a52d 100644 --- a/src/commands/broadcasts/list.ts +++ b/src/commands/broadcasts/list.ts @@ -52,7 +52,10 @@ To retrieve full details (html, from, subject), use: resend broadcasts get ` sdkCall: (resend) => resend.broadcasts.list(paginationOpts), onInteractive: (list) => { console.log(renderBroadcastsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'broadcasts list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/contact-properties/list.ts b/src/commands/contact-properties/list.ts index eccd819..eb8c058 100644 --- a/src/commands/contact-properties/list.ts +++ b/src/commands/contact-properties/list.ts @@ -60,7 +60,10 @@ export const listContactPropertiesCommand = new Command('list') sdkCall: (resend) => resend.contactProperties.list(paginationOpts), onInteractive: (list) => { console.log(renderContactPropertiesTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'contact-properties list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/contacts/list.ts b/src/commands/contacts/list.ts index 5fdb50f..a1953aa 100644 --- a/src/commands/contacts/list.ts +++ b/src/commands/contacts/list.ts @@ -49,7 +49,10 @@ Pagination: use --after or --before with a contact ID as the cursor. sdkCall: (resend) => resend.contacts.list(paginationOpts), onInteractive: (list) => { console.log(renderContactsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'contacts list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/domains/list.ts b/src/commands/domains/list.ts index 3448772..3444541 100644 --- a/src/commands/domains/list.ts +++ b/src/commands/domains/list.ts @@ -45,7 +45,10 @@ export const listDomainsCommand = new Command('list') sdkCall: (resend) => resend.domains.list(paginationOpts), onInteractive: (list) => { console.log(renderDomainsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'domains list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/emails/list.ts b/src/commands/emails/list.ts index 57353a1..2521b0f 100644 --- a/src/commands/emails/list.ts +++ b/src/commands/emails/list.ts @@ -76,7 +76,10 @@ export const listEmailsCommand = new Command('list') sdkCall: (resend) => resend.emails.list(paginationOpts), onInteractive: (list) => { console.log(renderSentEmailsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'emails list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/emails/receiving/attachments.ts b/src/commands/emails/receiving/attachments.ts index ed2d578..395e041 100644 --- a/src/commands/emails/receiving/attachments.ts +++ b/src/commands/emails/receiving/attachments.ts @@ -60,7 +60,10 @@ export const listAttachmentsCommand = new Command('attachments') }), onInteractive: (list) => { console.log(renderAttachmentsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, `emails receiving attachments ${emailId}`, { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/emails/receiving/list.ts b/src/commands/emails/receiving/list.ts index 614fedc..08b2f35 100644 --- a/src/commands/emails/receiving/list.ts +++ b/src/commands/emails/receiving/list.ts @@ -51,7 +51,10 @@ export const listReceivingCommand = new Command('list') sdkCall: (resend) => resend.emails.receiving.list(paginationOpts), onInteractive: (list) => { console.log(renderReceivingEmailsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'emails receiving list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/segments/list.ts b/src/commands/segments/list.ts index 24546cd..c8402a9 100644 --- a/src/commands/segments/list.ts +++ b/src/commands/segments/list.ts @@ -50,7 +50,10 @@ or "resend contacts add-segment".`, sdkCall: (resend) => resend.segments.list(paginationOpts), onInteractive: (list) => { console.log(renderSegmentsTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'segments list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/commands/webhooks/list.ts b/src/commands/webhooks/list.ts index fce5ff7..1a9a34c 100644 --- a/src/commands/webhooks/list.ts +++ b/src/commands/webhooks/list.ts @@ -47,7 +47,10 @@ The response includes has_more: true when additional pages exist.`, sdkCall: (resend) => resend.webhooks.list(paginationOpts), onInteractive: (list) => { console.log(renderWebhooksTable(list.data)); - printPaginationHint(list); + printPaginationHint(list, 'webhooks list', { + limit, + before: opts.before, + }); }, }, globalOpts, diff --git a/src/lib/pagination.ts b/src/lib/pagination.ts index f74a0d0..a8b832c 100644 --- a/src/lib/pagination.ts +++ b/src/lib/pagination.ts @@ -23,14 +23,26 @@ export function buildPaginationOpts( return after ? { limit, after } : before ? { limit, before } : { limit }; } -export function printPaginationHint(list: { - has_more: boolean; - data: Array<{ id: string }>; -}): void { - if (list.has_more && list.data.length > 0) { - const last = list.data[list.data.length - 1]; - console.log( - `\nMore results available. Use --after ${last.id} to fetch the next page.`, - ); +export function printPaginationHint( + list: { + has_more: boolean; + data: Array<{ id: string }>; + }, + command: string, + opts: { limit?: number; before?: string }, +): void { + if (!list.has_more || list.data.length === 0) { + return; } + + const backward = Boolean(opts.before); + const cursor = backward + ? list.data[0].id + : list.data[list.data.length - 1].id; + const flag = backward ? '--before' : '--after'; + const limitFlag = opts.limit ? ` --limit ${opts.limit}` : ''; + + console.log( + `\nFetch the next page:\n$ resend ${command} ${flag} ${cursor}${limitFlag}`, + ); }