-
Notifications
You must be signed in to change notification settings - Fork 33
feat: email attachments #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5bf9afe
feat: add emails attachments and attachment commands for outbound emails
felipefreitag 7ecc75a
feat: add interactive pickers to receiving attachment command
felipefreitag a9f7ed7
fix: spy on console.error instead of console.log in attachment error …
felipefreitag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Command } from '@commander-js/extra-typings'; | ||
| import { runGet } from '../../lib/actions'; | ||
| import type { GlobalOpts } from '../../lib/client'; | ||
| import { buildHelpText } from '../../lib/help-text'; | ||
| import { pickId } from '../../lib/prompts'; | ||
| import { attachmentPickerConfig, emailPickerConfig } from './utils'; | ||
|
|
||
| export const getAttachmentCommand = new Command('attachment') | ||
| .description('Retrieve a single attachment from a sent (outbound) email') | ||
| .argument('[emailId]', 'Email UUID') | ||
| .argument('[attachmentId]', 'Attachment UUID') | ||
| .addHelpText( | ||
| 'after', | ||
| buildHelpText({ | ||
| context: | ||
| 'The download_url is a signed URL that expires in ~1 hour. Download the file directly:\n resend emails attachment <emailId> <attachmentId> --json | jq -r .download_url | xargs curl -O', | ||
| output: | ||
| ' {"object":"attachment","id":"<uuid>","filename":"invoice.pdf","size":51200,"content_type":"application/pdf","content_disposition":"attachment","content_id":null,"download_url":"<signed-url>","expires_at":"<iso-date>"}', | ||
| errorCodes: ['auth_error', 'fetch_error'], | ||
| examples: [ | ||
| 'resend emails attachment <email-id> <attachment-id>', | ||
| 'resend emails attachment <email-id> <attachment-id> --json', | ||
| ], | ||
| }), | ||
| ) | ||
| .action(async (emailIdArg, attachmentIdArg, _opts, cmd) => { | ||
| const globalOpts = cmd.optsWithGlobals() as GlobalOpts; | ||
| const emailId = await pickId(emailIdArg, emailPickerConfig, globalOpts); | ||
| const attachmentId = await pickId( | ||
| attachmentIdArg, | ||
| attachmentPickerConfig(emailId), | ||
| globalOpts, | ||
| ); | ||
| await runGet( | ||
| { | ||
| loading: 'Fetching attachment...', | ||
| sdkCall: (resend) => | ||
| resend.emails.attachments.get({ emailId, id: attachmentId }), | ||
| onInteractive: (data) => { | ||
| console.log(`${data.filename ?? '(unnamed)'}`); | ||
| console.log(`ID: ${data.id}`); | ||
| console.log(`Content-Type: ${data.content_type}`); | ||
| console.log(`Size: ${data.size} bytes`); | ||
| console.log(`Disposition: ${data.content_disposition}`); | ||
| console.log(`Download URL: ${data.download_url}`); | ||
| console.log(`Expires: ${data.expires_at}`); | ||
| }, | ||
| }, | ||
| globalOpts, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { Command } from '@commander-js/extra-typings'; | ||
| import { runList } from '../../lib/actions'; | ||
| import type { GlobalOpts } from '../../lib/client'; | ||
| import { buildHelpText } from '../../lib/help-text'; | ||
| import { | ||
| buildPaginationOpts, | ||
| parseLimitOpt, | ||
| printPaginationHint, | ||
| } from '../../lib/pagination'; | ||
| import { pickId } from '../../lib/prompts'; | ||
| import { emailPickerConfig, renderAttachmentsTable } from './utils'; | ||
|
|
||
| export const listAttachmentsCommand = new Command('attachments') | ||
| .description('List attachments on a sent (outbound) email') | ||
| .argument('[emailId]', 'Email UUID') | ||
| .option( | ||
| '--limit <n>', | ||
| 'Maximum number of attachments to return (1-100)', | ||
| '10', | ||
| ) | ||
| .option( | ||
| '--after <cursor>', | ||
| 'Return attachments after this cursor (next page)', | ||
| ) | ||
| .option( | ||
| '--before <cursor>', | ||
| 'Return attachments before this cursor (previous page)', | ||
| ) | ||
| .addHelpText( | ||
| 'after', | ||
| buildHelpText({ | ||
| context: | ||
| 'Each attachment has a download_url (signed, expires ~1 hour).\nUse the attachment sub-command to retrieve a single attachment with its download URL:\n resend emails attachment <emailId> <attachmentId>\n\ncontent_disposition: "inline" means the attachment is embedded in the HTML body (e.g. an image).\ncontent_disposition: "attachment" means it is a standalone file download.', | ||
| output: | ||
| ' {"object":"list","has_more":false,"data":[{"id":"<uuid>","filename":"invoice.pdf","size":51200,"content_type":"application/pdf","content_disposition":"attachment","content_id":null,"download_url":"<url>","expires_at":"<iso-date>"}]}', | ||
| errorCodes: ['auth_error', 'invalid_limit', 'list_error'], | ||
| examples: [ | ||
| 'resend emails attachments <email-id>', | ||
| 'resend emails attachments <email-id> --json', | ||
| 'resend emails attachments <email-id> --limit 25 --json', | ||
| ], | ||
| }), | ||
| ) | ||
| .action(async (emailIdArg, opts, cmd) => { | ||
| const globalOpts = cmd.optsWithGlobals() as GlobalOpts; | ||
| const emailId = await pickId(emailIdArg, emailPickerConfig, globalOpts); | ||
|
|
||
| const limit = parseLimitOpt(opts.limit, globalOpts); | ||
| const paginationOpts = buildPaginationOpts( | ||
| limit, | ||
| opts.after, | ||
| opts.before, | ||
| globalOpts, | ||
| ); | ||
|
|
||
| await runList( | ||
| { | ||
| loading: 'Fetching attachments...', | ||
| sdkCall: (resend) => | ||
| resend.emails.attachments.list({ | ||
| emailId, | ||
| ...paginationOpts, | ||
| }), | ||
| onInteractive: (list) => { | ||
| console.log(renderAttachmentsTable(list.data)); | ||
| printPaginationHint(list, `emails attachments ${emailId}`, { | ||
| limit, | ||
| before: opts.before, | ||
| apiKey: globalOpts.apiKey, | ||
| profile: globalOpts.profile, | ||
| }); | ||
| }, | ||
| }, | ||
| globalOpts, | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.