Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/commands/broadcasts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ To retrieve full details (html, from, subject), use: resend broadcasts get <id>`
sdkCall: (resend) => resend.broadcasts.list(paginationOpts),
onInteractive: (list) => {
console.log(renderBroadcastsTable(list.data));
printPaginationHint(list);
printPaginationHint(list, 'broadcasts list', {
limit,
before: opts.before,
});
},
},
globalOpts,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/contact-properties/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/contacts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/domains/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/emails/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/emails/receiving/attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/emails/receiving/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/segments/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/commands/webhooks/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 21 additions & 9 deletions src/lib/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
}