resend-cli 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +14 -0
- package/.github/scripts/pr-title-check.js +34 -0
- package/.github/workflows/ci.yml +32 -0
- package/.github/workflows/pr-title-check.yml +13 -0
- package/.github/workflows/release.yml +93 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -21
- package/README.md +416 -19
- package/biome.json +36 -0
- package/bun.lock +76 -0
- package/bunfig.toml +2 -0
- package/install.ps1 +140 -0
- package/install.sh +294 -0
- package/package.json +43 -22
- package/src/cli.ts +65 -0
- package/src/commands/api-keys/create.ts +114 -0
- package/src/commands/api-keys/delete.ts +47 -0
- package/src/commands/api-keys/index.ts +26 -0
- package/src/commands/api-keys/list.ts +35 -0
- package/src/commands/api-keys/utils.ts +8 -0
- package/src/commands/auth/index.ts +20 -0
- package/src/commands/auth/login.ts +211 -0
- package/src/commands/auth/logout.ts +105 -0
- package/src/commands/broadcasts/create.ts +196 -0
- package/src/commands/broadcasts/delete.ts +46 -0
- package/src/commands/broadcasts/get.ts +59 -0
- package/src/commands/broadcasts/index.ts +43 -0
- package/src/commands/broadcasts/list.ts +60 -0
- package/src/commands/broadcasts/send.ts +56 -0
- package/src/commands/broadcasts/update.ts +95 -0
- package/src/commands/broadcasts/utils.ts +35 -0
- package/src/commands/contact-properties/create.ts +118 -0
- package/src/commands/contact-properties/delete.ts +48 -0
- package/src/commands/contact-properties/get.ts +46 -0
- package/src/commands/contact-properties/index.ts +48 -0
- package/src/commands/contact-properties/list.ts +68 -0
- package/src/commands/contact-properties/update.ts +88 -0
- package/src/commands/contact-properties/utils.ts +17 -0
- package/src/commands/contacts/add-segment.ts +78 -0
- package/src/commands/contacts/create.ts +122 -0
- package/src/commands/contacts/delete.ts +49 -0
- package/src/commands/contacts/get.ts +53 -0
- package/src/commands/contacts/index.ts +58 -0
- package/src/commands/contacts/list.ts +57 -0
- package/src/commands/contacts/remove-segment.ts +48 -0
- package/src/commands/contacts/segments.ts +39 -0
- package/src/commands/contacts/topics.ts +45 -0
- package/src/commands/contacts/update-topics.ts +90 -0
- package/src/commands/contacts/update.ts +77 -0
- package/src/commands/contacts/utils.ts +119 -0
- package/src/commands/doctor.ts +298 -0
- package/src/commands/domains/create.ts +83 -0
- package/src/commands/domains/delete.ts +42 -0
- package/src/commands/domains/get.ts +47 -0
- package/src/commands/domains/index.ts +35 -0
- package/src/commands/domains/list.ts +53 -0
- package/src/commands/domains/update.ts +75 -0
- package/src/commands/domains/utils.ts +44 -0
- package/src/commands/domains/verify.ts +38 -0
- package/src/commands/emails/batch.ts +140 -0
- package/src/commands/emails/index.ts +24 -0
- package/src/commands/emails/receiving/attachment.ts +55 -0
- package/src/commands/emails/receiving/attachments.ts +68 -0
- package/src/commands/emails/receiving/get.ts +58 -0
- package/src/commands/emails/receiving/index.ts +28 -0
- package/src/commands/emails/receiving/list.ts +59 -0
- package/src/commands/emails/receiving/utils.ts +38 -0
- package/src/commands/emails/send.ts +189 -0
- package/src/commands/segments/create.ts +50 -0
- package/src/commands/segments/delete.ts +47 -0
- package/src/commands/segments/get.ts +38 -0
- package/src/commands/segments/index.ts +36 -0
- package/src/commands/segments/list.ts +58 -0
- package/src/commands/segments/utils.ts +7 -0
- package/src/commands/teams/index.ts +10 -0
- package/src/commands/teams/list.ts +35 -0
- package/src/commands/teams/remove.ts +83 -0
- package/src/commands/teams/switch.ts +73 -0
- package/src/commands/topics/create.ts +73 -0
- package/src/commands/topics/delete.ts +47 -0
- package/src/commands/topics/get.ts +42 -0
- package/src/commands/topics/index.ts +42 -0
- package/src/commands/topics/list.ts +34 -0
- package/src/commands/topics/update.ts +59 -0
- package/src/commands/topics/utils.ts +16 -0
- package/src/commands/webhooks/create.ts +128 -0
- package/src/commands/webhooks/delete.ts +49 -0
- package/src/commands/webhooks/get.ts +42 -0
- package/src/commands/webhooks/index.ts +44 -0
- package/src/commands/webhooks/list.ts +55 -0
- package/src/commands/webhooks/update.ts +83 -0
- package/src/commands/webhooks/utils.ts +36 -0
- package/src/commands/whoami.ts +71 -0
- package/src/lib/actions.ts +157 -0
- package/src/lib/client.ts +29 -0
- package/src/lib/config.ts +211 -0
- package/src/lib/files.ts +15 -0
- package/src/lib/help-text.ts +36 -0
- package/src/lib/output.ts +54 -0
- package/src/lib/pagination.ts +36 -0
- package/src/lib/prompts.ts +149 -0
- package/src/lib/spinner.ts +89 -0
- package/src/lib/table.ts +57 -0
- package/src/lib/tty.ts +28 -0
- package/src/lib/version.ts +4 -0
- package/tests/commands/api-keys/create.test.ts +195 -0
- package/tests/commands/api-keys/delete.test.ts +156 -0
- package/tests/commands/api-keys/list.test.ts +133 -0
- package/tests/commands/auth/login.test.ts +119 -0
- package/tests/commands/auth/logout.test.ts +146 -0
- package/tests/commands/broadcasts/create.test.ts +447 -0
- package/tests/commands/broadcasts/delete.test.ts +182 -0
- package/tests/commands/broadcasts/get.test.ts +146 -0
- package/tests/commands/broadcasts/list.test.ts +196 -0
- package/tests/commands/broadcasts/send.test.ts +161 -0
- package/tests/commands/broadcasts/update.test.ts +283 -0
- package/tests/commands/contact-properties/create.test.ts +250 -0
- package/tests/commands/contact-properties/delete.test.ts +183 -0
- package/tests/commands/contact-properties/get.test.ts +144 -0
- package/tests/commands/contact-properties/list.test.ts +180 -0
- package/tests/commands/contact-properties/update.test.ts +216 -0
- package/tests/commands/contacts/add-segment.test.ts +188 -0
- package/tests/commands/contacts/create.test.ts +270 -0
- package/tests/commands/contacts/delete.test.ts +192 -0
- package/tests/commands/contacts/get.test.ts +148 -0
- package/tests/commands/contacts/list.test.ts +175 -0
- package/tests/commands/contacts/remove-segment.test.ts +166 -0
- package/tests/commands/contacts/segments.test.ts +167 -0
- package/tests/commands/contacts/topics.test.ts +163 -0
- package/tests/commands/contacts/update-topics.test.ts +247 -0
- package/tests/commands/contacts/update.test.ts +205 -0
- package/tests/commands/doctor.test.ts +165 -0
- package/tests/commands/domains/create.test.ts +192 -0
- package/tests/commands/domains/delete.test.ts +156 -0
- package/tests/commands/domains/get.test.ts +137 -0
- package/tests/commands/domains/list.test.ts +164 -0
- package/tests/commands/domains/update.test.ts +223 -0
- package/tests/commands/domains/verify.test.ts +117 -0
- package/tests/commands/emails/batch.test.ts +313 -0
- package/tests/commands/emails/receiving/attachment.test.ts +140 -0
- package/tests/commands/emails/receiving/attachments.test.ts +168 -0
- package/tests/commands/emails/receiving/get.test.ts +140 -0
- package/tests/commands/emails/receiving/list.test.ts +181 -0
- package/tests/commands/emails/send.test.ts +309 -0
- package/tests/commands/segments/create.test.ts +163 -0
- package/tests/commands/segments/delete.test.ts +182 -0
- package/tests/commands/segments/get.test.ts +137 -0
- package/tests/commands/segments/list.test.ts +173 -0
- package/tests/commands/teams/list.test.ts +63 -0
- package/tests/commands/teams/remove.test.ts +103 -0
- package/tests/commands/teams/switch.test.ts +96 -0
- package/tests/commands/topics/create.test.ts +191 -0
- package/tests/commands/topics/delete.test.ts +156 -0
- package/tests/commands/topics/get.test.ts +125 -0
- package/tests/commands/topics/list.test.ts +124 -0
- package/tests/commands/topics/update.test.ts +177 -0
- package/tests/commands/webhooks/create.test.ts +224 -0
- package/tests/commands/webhooks/delete.test.ts +156 -0
- package/tests/commands/webhooks/get.test.ts +125 -0
- package/tests/commands/webhooks/list.test.ts +177 -0
- package/tests/commands/webhooks/update.test.ts +206 -0
- package/tests/commands/whoami.test.ts +99 -0
- package/tests/helpers.ts +93 -0
- package/tests/lib/client.test.ts +71 -0
- package/tests/lib/config.test.ts +414 -0
- package/tests/lib/files.test.ts +65 -0
- package/tests/lib/help-text.test.ts +96 -0
- package/tests/lib/output.test.ts +127 -0
- package/tests/lib/prompts.test.ts +178 -0
- package/tests/lib/spinner.test.ts +146 -0
- package/tests/lib/table.test.ts +63 -0
- package/tests/lib/tty.test.ts +85 -0
- package/tsconfig.json +14 -0
- package/src/index.js +0 -72
- package/src/routes.js +0 -37
- package/src/sections/apikeys.js +0 -99
- package/src/sections/audiences.js +0 -84
- package/src/sections/contacts.js +0 -177
- package/src/sections/domain.js +0 -195
- package/src/sections/email.js +0 -132
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import * as p from '@clack/prompts';
|
|
2
|
+
import { Command } from '@commander-js/extra-typings';
|
|
3
|
+
import type { CreateBroadcastOptions } from 'resend';
|
|
4
|
+
import { runCreate } from '../../lib/actions';
|
|
5
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
6
|
+
import { readFile } from '../../lib/files';
|
|
7
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
8
|
+
import { outputError } from '../../lib/output';
|
|
9
|
+
import { cancelAndExit } from '../../lib/prompts';
|
|
10
|
+
import { isInteractive } from '../../lib/tty';
|
|
11
|
+
|
|
12
|
+
export const createBroadcastCommand = new Command('create')
|
|
13
|
+
.description('Create a broadcast draft (or send immediately with --send)')
|
|
14
|
+
.option('--from <address>', 'Sender address — required')
|
|
15
|
+
.option('--subject <subject>', 'Email subject — required')
|
|
16
|
+
.option('--segment-id <id>', 'Target segment ID — required')
|
|
17
|
+
.option(
|
|
18
|
+
'--html <html>',
|
|
19
|
+
'HTML body (supports {{{FIRST_NAME|fallback}}} triple-brace variable interpolation)',
|
|
20
|
+
)
|
|
21
|
+
.option(
|
|
22
|
+
'--html-file <path>',
|
|
23
|
+
'Path to an HTML file for the body (supports {{{FIRST_NAME|fallback}}} variable interpolation)',
|
|
24
|
+
)
|
|
25
|
+
.option('--text <text>', 'Plain-text body')
|
|
26
|
+
.option('--name <name>', 'Internal label for the broadcast (optional)')
|
|
27
|
+
.option('--reply-to <address>', 'Reply-to address (optional)')
|
|
28
|
+
.option(
|
|
29
|
+
'--preview-text <text>',
|
|
30
|
+
'Preview text shown in inbox below the subject line (optional)',
|
|
31
|
+
)
|
|
32
|
+
.option(
|
|
33
|
+
'--topic-id <id>',
|
|
34
|
+
'Associate with a topic for subscription filtering (optional)',
|
|
35
|
+
)
|
|
36
|
+
.option('--send', 'Send immediately on create instead of saving as draft')
|
|
37
|
+
.option(
|
|
38
|
+
'--scheduled-at <datetime>',
|
|
39
|
+
'Schedule delivery — ISO 8601 or natural language e.g. "in 1 hour", "tomorrow at 9am ET" (only valid with --send)',
|
|
40
|
+
)
|
|
41
|
+
.addHelpText(
|
|
42
|
+
'after',
|
|
43
|
+
buildHelpText({
|
|
44
|
+
context: `Non-interactive: --from, --subject, and --segment-id are required.
|
|
45
|
+
Body: provide exactly one of --html, --html-file, or --text.
|
|
46
|
+
|
|
47
|
+
Variable interpolation:
|
|
48
|
+
HTML bodies support triple-brace syntax for contact properties.
|
|
49
|
+
Example: {{{FIRST_NAME|Friend}}} — uses FIRST_NAME or falls back to "Friend".
|
|
50
|
+
|
|
51
|
+
Scheduling:
|
|
52
|
+
Use --scheduled-at with --send to schedule delivery.
|
|
53
|
+
Accepts ISO 8601 (e.g. 2026-08-05T11:52:01Z) or natural language (e.g. "in 1 hour").
|
|
54
|
+
--scheduled-at without --send is ignored.`,
|
|
55
|
+
output: ` {"id":"<broadcast-id>"}`,
|
|
56
|
+
errorCodes: [
|
|
57
|
+
'auth_error',
|
|
58
|
+
'missing_from',
|
|
59
|
+
'missing_subject',
|
|
60
|
+
'missing_segment',
|
|
61
|
+
'missing_body',
|
|
62
|
+
'file_read_error',
|
|
63
|
+
'create_error',
|
|
64
|
+
],
|
|
65
|
+
examples: [
|
|
66
|
+
'resend broadcasts create --from hello@domain.com --subject "Weekly Update" --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --html "<p>Hello {{{FIRST_NAME|there}}}</p>"',
|
|
67
|
+
'resend broadcasts create --from hello@domain.com --subject "Launch" --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --html-file ./email.html --send',
|
|
68
|
+
'resend broadcasts create --from hello@domain.com --subject "Launch" --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --text "Hello!" --send --scheduled-at "tomorrow at 9am ET"',
|
|
69
|
+
'resend broadcasts create --from hello@domain.com --subject "News" --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --html "<p>Hi</p>" --json',
|
|
70
|
+
],
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
.action(async (opts, cmd) => {
|
|
74
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
75
|
+
|
|
76
|
+
let from = opts.from;
|
|
77
|
+
let subject = opts.subject;
|
|
78
|
+
let segmentId = opts.segmentId;
|
|
79
|
+
|
|
80
|
+
if (!from) {
|
|
81
|
+
if (!isInteractive()) {
|
|
82
|
+
outputError(
|
|
83
|
+
{ message: 'Missing --from flag.', code: 'missing_from' },
|
|
84
|
+
{ json: globalOpts.json },
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const result = await p.text({
|
|
88
|
+
message: 'From address',
|
|
89
|
+
placeholder: 'hello@domain.com',
|
|
90
|
+
validate: (v) => (!v ? 'Required' : undefined),
|
|
91
|
+
});
|
|
92
|
+
if (p.isCancel(result)) {
|
|
93
|
+
cancelAndExit('Cancelled.');
|
|
94
|
+
}
|
|
95
|
+
from = result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!subject) {
|
|
99
|
+
if (!isInteractive()) {
|
|
100
|
+
outputError(
|
|
101
|
+
{ message: 'Missing --subject flag.', code: 'missing_subject' },
|
|
102
|
+
{ json: globalOpts.json },
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const result = await p.text({
|
|
106
|
+
message: 'Subject',
|
|
107
|
+
placeholder: 'Weekly Newsletter',
|
|
108
|
+
validate: (v) => (!v ? 'Required' : undefined),
|
|
109
|
+
});
|
|
110
|
+
if (p.isCancel(result)) {
|
|
111
|
+
cancelAndExit('Cancelled.');
|
|
112
|
+
}
|
|
113
|
+
subject = result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!segmentId) {
|
|
117
|
+
if (!isInteractive()) {
|
|
118
|
+
outputError(
|
|
119
|
+
{ message: 'Missing --segment-id flag.', code: 'missing_segment' },
|
|
120
|
+
{ json: globalOpts.json },
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const result = await p.text({
|
|
124
|
+
message: 'Segment ID',
|
|
125
|
+
placeholder: '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
|
|
126
|
+
validate: (v) => (!v ? 'Required' : undefined),
|
|
127
|
+
});
|
|
128
|
+
if (p.isCancel(result)) {
|
|
129
|
+
cancelAndExit('Cancelled.');
|
|
130
|
+
}
|
|
131
|
+
segmentId = result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let html = opts.html;
|
|
135
|
+
let text = opts.text;
|
|
136
|
+
|
|
137
|
+
if (opts.htmlFile) {
|
|
138
|
+
html = readFile(opts.htmlFile, globalOpts);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!html && !text) {
|
|
142
|
+
if (!isInteractive()) {
|
|
143
|
+
outputError(
|
|
144
|
+
{
|
|
145
|
+
message: 'Missing body. Provide --html, --html-file, or --text.',
|
|
146
|
+
code: 'missing_body',
|
|
147
|
+
},
|
|
148
|
+
{ json: globalOpts.json },
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const result = await p.text({
|
|
152
|
+
message: 'Body (plain text)',
|
|
153
|
+
placeholder: 'Hello {{{FIRST_NAME|there}}}!',
|
|
154
|
+
validate: (v) => (!v ? 'Required' : undefined),
|
|
155
|
+
});
|
|
156
|
+
if (p.isCancel(result)) {
|
|
157
|
+
cancelAndExit('Cancelled.');
|
|
158
|
+
}
|
|
159
|
+
text = result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
await runCreate(
|
|
163
|
+
{
|
|
164
|
+
spinner: {
|
|
165
|
+
loading: 'Creating broadcast...',
|
|
166
|
+
success: opts.send ? 'Broadcast sent' : 'Broadcast created',
|
|
167
|
+
fail: 'Failed to create broadcast',
|
|
168
|
+
},
|
|
169
|
+
sdkCall: (resend) =>
|
|
170
|
+
resend.broadcasts.create({
|
|
171
|
+
from,
|
|
172
|
+
subject,
|
|
173
|
+
segmentId,
|
|
174
|
+
...(html && { html }),
|
|
175
|
+
...(text && { text }),
|
|
176
|
+
...(opts.name && { name: opts.name }),
|
|
177
|
+
...(opts.replyTo && { replyTo: opts.replyTo }),
|
|
178
|
+
...(opts.previewText && { previewText: opts.previewText }),
|
|
179
|
+
...(opts.topicId && { topicId: opts.topicId }),
|
|
180
|
+
...(opts.send && { send: true as const }),
|
|
181
|
+
...(opts.send &&
|
|
182
|
+
opts.scheduledAt && { scheduledAt: opts.scheduledAt }),
|
|
183
|
+
} as CreateBroadcastOptions),
|
|
184
|
+
onInteractive: (d) => {
|
|
185
|
+
if (opts.send) {
|
|
186
|
+
console.log(`\nBroadcast sent: ${d.id}`);
|
|
187
|
+
} else {
|
|
188
|
+
console.log(`\nBroadcast created: ${d.id}`);
|
|
189
|
+
console.log('Status: draft');
|
|
190
|
+
console.log(`\nSend it with: resend broadcasts send ${d.id}`);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
globalOpts,
|
|
195
|
+
);
|
|
196
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runDelete } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
|
|
6
|
+
export const deleteBroadcastCommand = new Command('delete')
|
|
7
|
+
.alias('rm')
|
|
8
|
+
.description(
|
|
9
|
+
'Delete a broadcast — draft broadcasts are removed; scheduled broadcasts are cancelled before delivery',
|
|
10
|
+
)
|
|
11
|
+
.argument('<id>', 'Broadcast ID')
|
|
12
|
+
.option('--yes', 'Skip confirmation prompt')
|
|
13
|
+
.addHelpText(
|
|
14
|
+
'after',
|
|
15
|
+
buildHelpText({
|
|
16
|
+
context: `Warning: Deleting a scheduled broadcast cancels its delivery immediately.
|
|
17
|
+
Only draft and scheduled broadcasts can be deleted; sent broadcasts cannot.
|
|
18
|
+
|
|
19
|
+
Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.`,
|
|
20
|
+
output: ` {"object":"broadcast","id":"<id>","deleted":true}`,
|
|
21
|
+
errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
|
|
22
|
+
examples: [
|
|
23
|
+
'resend broadcasts delete d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --yes',
|
|
24
|
+
'resend broadcasts delete d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --yes --json',
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
.action(async (id, opts, cmd) => {
|
|
29
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
30
|
+
await runDelete(
|
|
31
|
+
id,
|
|
32
|
+
!!opts.yes,
|
|
33
|
+
{
|
|
34
|
+
confirmMessage: `Delete broadcast ${id}?\nIf scheduled, delivery will be cancelled.`,
|
|
35
|
+
spinner: {
|
|
36
|
+
loading: 'Deleting broadcast...',
|
|
37
|
+
success: 'Broadcast deleted',
|
|
38
|
+
fail: 'Failed to delete broadcast',
|
|
39
|
+
},
|
|
40
|
+
object: 'broadcast',
|
|
41
|
+
successMsg: 'Broadcast deleted.',
|
|
42
|
+
sdkCall: (resend) => resend.broadcasts.remove(id),
|
|
43
|
+
},
|
|
44
|
+
globalOpts,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runGet } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
import { broadcastStatusIndicator } from './utils';
|
|
6
|
+
|
|
7
|
+
export const getBroadcastCommand = new Command('get')
|
|
8
|
+
.description(
|
|
9
|
+
'Retrieve full details for a broadcast including HTML body, status, and delivery times',
|
|
10
|
+
)
|
|
11
|
+
.argument('<id>', 'Broadcast ID')
|
|
12
|
+
.addHelpText(
|
|
13
|
+
'after',
|
|
14
|
+
buildHelpText({
|
|
15
|
+
context: `Note: The list command returns summary objects without html/text/from/subject.
|
|
16
|
+
Use this command to retrieve the full broadcast payload.`,
|
|
17
|
+
output: ` {"id":"...","object":"broadcast","name":"...","segment_id":"...","from":"...","subject":"...","status":"draft|queued|sent","created_at":"...","scheduled_at":null,"sent_at":null}`,
|
|
18
|
+
errorCodes: ['auth_error', 'fetch_error'],
|
|
19
|
+
examples: [
|
|
20
|
+
'resend broadcasts get d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
|
|
21
|
+
'resend broadcasts get d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --json',
|
|
22
|
+
],
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
.action(async (id, _opts, cmd) => {
|
|
26
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
27
|
+
await runGet(
|
|
28
|
+
{
|
|
29
|
+
spinner: {
|
|
30
|
+
loading: 'Fetching broadcast...',
|
|
31
|
+
success: 'Broadcast fetched',
|
|
32
|
+
fail: 'Failed to fetch broadcast',
|
|
33
|
+
},
|
|
34
|
+
sdkCall: (resend) => resend.broadcasts.get(id),
|
|
35
|
+
onInteractive: (b) => {
|
|
36
|
+
console.log(`\nBroadcast: ${b.id}`);
|
|
37
|
+
console.log(` Status: ${broadcastStatusIndicator(b.status)}`);
|
|
38
|
+
console.log(` Name: ${b.name ?? '(untitled)'}`);
|
|
39
|
+
console.log(` From: ${b.from ?? '—'}`);
|
|
40
|
+
console.log(` Subject: ${b.subject ?? '—'}`);
|
|
41
|
+
console.log(` Segment: ${b.segment_id ?? '—'}`);
|
|
42
|
+
if (b.preview_text) {
|
|
43
|
+
console.log(` Preview: ${b.preview_text}`);
|
|
44
|
+
}
|
|
45
|
+
if (b.topic_id) {
|
|
46
|
+
console.log(` Topic: ${b.topic_id}`);
|
|
47
|
+
}
|
|
48
|
+
console.log(` Created: ${b.created_at}`);
|
|
49
|
+
if (b.scheduled_at) {
|
|
50
|
+
console.log(` Scheduled: ${b.scheduled_at}`);
|
|
51
|
+
}
|
|
52
|
+
if (b.sent_at) {
|
|
53
|
+
console.log(` Sent: ${b.sent_at}`);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
globalOpts,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
3
|
+
import { createBroadcastCommand } from './create';
|
|
4
|
+
import { deleteBroadcastCommand } from './delete';
|
|
5
|
+
import { getBroadcastCommand } from './get';
|
|
6
|
+
import { listBroadcastsCommand } from './list';
|
|
7
|
+
import { sendBroadcastCommand } from './send';
|
|
8
|
+
import { updateBroadcastCommand } from './update';
|
|
9
|
+
|
|
10
|
+
export const broadcastsCommand = new Command('broadcasts')
|
|
11
|
+
.description('Manage broadcasts — bulk email to a segment of contacts')
|
|
12
|
+
.addHelpText(
|
|
13
|
+
'after',
|
|
14
|
+
buildHelpText({
|
|
15
|
+
context: `Lifecycle:
|
|
16
|
+
Broadcasts follow a draft → send flow:
|
|
17
|
+
1. create — creates a draft (or sends immediately with --send)
|
|
18
|
+
2. send — sends an API-created draft (dashboard broadcasts cannot be sent via API)
|
|
19
|
+
Scheduled broadcasts can be deleted to cancel delivery; sent broadcasts are immutable.
|
|
20
|
+
|
|
21
|
+
Template variables:
|
|
22
|
+
HTML bodies support triple-brace interpolation for contact properties.
|
|
23
|
+
Example: {{{FIRST_NAME|Friend}}} — uses FIRST_NAME or falls back to "Friend".
|
|
24
|
+
|
|
25
|
+
Scheduling:
|
|
26
|
+
--scheduled-at accepts ISO 8601 or natural language e.g. "in 1 hour", "tomorrow at 9am ET".`,
|
|
27
|
+
examples: [
|
|
28
|
+
'resend broadcasts list',
|
|
29
|
+
'resend broadcasts create --from hello@domain.com --subject "Launch" --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --html "<p>Hi {{{FIRST_NAME|there}}}</p>"',
|
|
30
|
+
'resend broadcasts send d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
|
|
31
|
+
'resend broadcasts send d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --scheduled-at "in 1 hour"',
|
|
32
|
+
'resend broadcasts get d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
|
|
33
|
+
'resend broadcasts update d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --subject "Updated Subject"',
|
|
34
|
+
'resend broadcasts delete d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --yes',
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
)
|
|
38
|
+
.addCommand(createBroadcastCommand)
|
|
39
|
+
.addCommand(sendBroadcastCommand)
|
|
40
|
+
.addCommand(getBroadcastCommand)
|
|
41
|
+
.addCommand(listBroadcastsCommand, { isDefault: true })
|
|
42
|
+
.addCommand(updateBroadcastCommand)
|
|
43
|
+
.addCommand(deleteBroadcastCommand);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runList } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
import {
|
|
6
|
+
buildPaginationOpts,
|
|
7
|
+
parseLimitOpt,
|
|
8
|
+
printPaginationHint,
|
|
9
|
+
} from '../../lib/pagination';
|
|
10
|
+
import { renderBroadcastsTable } from './utils';
|
|
11
|
+
|
|
12
|
+
export const listBroadcastsCommand = new Command('list')
|
|
13
|
+
.alias('ls')
|
|
14
|
+
.description(
|
|
15
|
+
'List broadcasts — returns summary objects (use "get <id>" for full details including html/text)',
|
|
16
|
+
)
|
|
17
|
+
.option('--limit <n>', 'Maximum number of results to return (1-100)', '10')
|
|
18
|
+
.option(
|
|
19
|
+
'--after <cursor>',
|
|
20
|
+
'Cursor for forward pagination — list items after this ID',
|
|
21
|
+
)
|
|
22
|
+
.option(
|
|
23
|
+
'--before <cursor>',
|
|
24
|
+
'Cursor for backward pagination — list items before this ID',
|
|
25
|
+
)
|
|
26
|
+
.addHelpText(
|
|
27
|
+
'after',
|
|
28
|
+
buildHelpText({
|
|
29
|
+
context: `Note: List results include name, status, created_at, and id only.
|
|
30
|
+
To retrieve full details (html, from, subject), use: resend broadcasts get <id>`,
|
|
31
|
+
output: ` {"object":"list","has_more":false,"data":[{"id":"...","name":"...","status":"draft|queued|sent","created_at":"..."}]}`,
|
|
32
|
+
errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
|
|
33
|
+
examples: [
|
|
34
|
+
'resend broadcasts list',
|
|
35
|
+
'resend broadcasts list --limit 5',
|
|
36
|
+
'resend broadcasts list --after d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --limit 10',
|
|
37
|
+
'resend broadcasts list --json',
|
|
38
|
+
],
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
.action(async (opts, cmd) => {
|
|
42
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
43
|
+
const limit = parseLimitOpt(opts.limit, globalOpts);
|
|
44
|
+
const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
|
|
45
|
+
await runList(
|
|
46
|
+
{
|
|
47
|
+
spinner: {
|
|
48
|
+
loading: 'Fetching broadcasts...',
|
|
49
|
+
success: 'Broadcasts fetched',
|
|
50
|
+
fail: 'Failed to list broadcasts',
|
|
51
|
+
},
|
|
52
|
+
sdkCall: (resend) => resend.broadcasts.list(paginationOpts),
|
|
53
|
+
onInteractive: (list) => {
|
|
54
|
+
console.log(renderBroadcastsTable(list.data));
|
|
55
|
+
printPaginationHint(list);
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
globalOpts,
|
|
59
|
+
);
|
|
60
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runWrite } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
|
|
6
|
+
export const sendBroadcastCommand = new Command('send')
|
|
7
|
+
.description(
|
|
8
|
+
'Send a draft broadcast (API-created drafts only — dashboard broadcasts cannot be sent via API)',
|
|
9
|
+
)
|
|
10
|
+
.argument('<id>', 'Broadcast ID')
|
|
11
|
+
.option(
|
|
12
|
+
'--scheduled-at <datetime>',
|
|
13
|
+
'Schedule delivery — ISO 8601 or natural language e.g. "in 1 hour", "tomorrow at 9am ET"',
|
|
14
|
+
)
|
|
15
|
+
.addHelpText(
|
|
16
|
+
'after',
|
|
17
|
+
buildHelpText({
|
|
18
|
+
context: `Note: Only broadcasts created via the API can be sent via this command.
|
|
19
|
+
Broadcasts created in the Resend dashboard cannot be sent programmatically.
|
|
20
|
+
|
|
21
|
+
Scheduling:
|
|
22
|
+
--scheduled-at accepts ISO 8601 (e.g. 2026-08-05T11:52:01Z) or
|
|
23
|
+
natural language (e.g. "in 1 hour", "tomorrow at 9am ET").`,
|
|
24
|
+
output: ` {"id":"<broadcast-id>"}`,
|
|
25
|
+
errorCodes: ['auth_error', 'send_error'],
|
|
26
|
+
examples: [
|
|
27
|
+
'resend broadcasts send d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
|
|
28
|
+
'resend broadcasts send d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --scheduled-at "in 1 hour"',
|
|
29
|
+
'resend broadcasts send d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --scheduled-at "2026-08-05T11:52:01Z" --json',
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
.action(async (id, opts, cmd) => {
|
|
34
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
35
|
+
|
|
36
|
+
const successMsg = opts.scheduledAt
|
|
37
|
+
? `\nBroadcast scheduled: ${id} (sends: ${opts.scheduledAt})`
|
|
38
|
+
: `\nBroadcast sent: ${id}`;
|
|
39
|
+
|
|
40
|
+
await runWrite(
|
|
41
|
+
{
|
|
42
|
+
spinner: {
|
|
43
|
+
loading: 'Sending broadcast...',
|
|
44
|
+
success: 'Broadcast sent',
|
|
45
|
+
fail: 'Failed to send broadcast',
|
|
46
|
+
},
|
|
47
|
+
sdkCall: (resend) =>
|
|
48
|
+
resend.broadcasts.send(id, {
|
|
49
|
+
...(opts.scheduledAt && { scheduledAt: opts.scheduledAt }),
|
|
50
|
+
}),
|
|
51
|
+
errorCode: 'send_error',
|
|
52
|
+
successMsg,
|
|
53
|
+
},
|
|
54
|
+
globalOpts,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { runWrite } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { readFile } from '../../lib/files';
|
|
5
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
6
|
+
import { outputError } from '../../lib/output';
|
|
7
|
+
|
|
8
|
+
export const updateBroadcastCommand = new Command('update')
|
|
9
|
+
.description(
|
|
10
|
+
'Update a draft broadcast — only drafts can be updated; sent broadcasts are immutable',
|
|
11
|
+
)
|
|
12
|
+
.argument('<id>', 'Broadcast ID')
|
|
13
|
+
.option('--from <address>', 'Update sender address')
|
|
14
|
+
.option('--subject <subject>', 'Update subject')
|
|
15
|
+
.option(
|
|
16
|
+
'--html <html>',
|
|
17
|
+
'Update HTML body (supports {{{FIRST_NAME|fallback}}} variable interpolation)',
|
|
18
|
+
)
|
|
19
|
+
.option(
|
|
20
|
+
'--html-file <path>',
|
|
21
|
+
'Path to an HTML file to replace the body (supports {{{FIRST_NAME|fallback}}} variable interpolation)',
|
|
22
|
+
)
|
|
23
|
+
.option('--text <text>', 'Update plain-text body')
|
|
24
|
+
.option('--name <name>', 'Update internal label')
|
|
25
|
+
.addHelpText(
|
|
26
|
+
'after',
|
|
27
|
+
buildHelpText({
|
|
28
|
+
context: `Note: Only draft broadcasts can be updated.
|
|
29
|
+
If the broadcast is already sent or sending, the API will return an error.
|
|
30
|
+
|
|
31
|
+
Variable interpolation:
|
|
32
|
+
HTML bodies support triple-brace syntax for contact properties.
|
|
33
|
+
Example: {{{FIRST_NAME|Friend}}} — uses FIRST_NAME or falls back to "Friend".`,
|
|
34
|
+
output: ` {"id":"<broadcast-id>"}`,
|
|
35
|
+
errorCodes: [
|
|
36
|
+
'auth_error',
|
|
37
|
+
'no_changes',
|
|
38
|
+
'file_read_error',
|
|
39
|
+
'update_error',
|
|
40
|
+
],
|
|
41
|
+
examples: [
|
|
42
|
+
'resend broadcasts update d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --subject "Updated Subject"',
|
|
43
|
+
'resend broadcasts update d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --html-file ./new-email.html',
|
|
44
|
+
'resend broadcasts update d1c2b3a4-5e6f-7a8b-9c0d-e1f2a3b4c5d6 --name "Q1 Newsletter" --from "news@domain.com" --json',
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
)
|
|
48
|
+
.action(async (id, opts, cmd) => {
|
|
49
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
!opts.from &&
|
|
53
|
+
!opts.subject &&
|
|
54
|
+
!opts.html &&
|
|
55
|
+
!opts.htmlFile &&
|
|
56
|
+
!opts.text &&
|
|
57
|
+
!opts.name
|
|
58
|
+
) {
|
|
59
|
+
outputError(
|
|
60
|
+
{
|
|
61
|
+
message:
|
|
62
|
+
'Provide at least one option to update: --from, --subject, --html, --html-file, --text, or --name.',
|
|
63
|
+
code: 'no_changes',
|
|
64
|
+
},
|
|
65
|
+
{ json: globalOpts.json },
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let html = opts.html;
|
|
70
|
+
|
|
71
|
+
if (opts.htmlFile) {
|
|
72
|
+
html = readFile(opts.htmlFile, globalOpts);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await runWrite(
|
|
76
|
+
{
|
|
77
|
+
spinner: {
|
|
78
|
+
loading: 'Updating broadcast...',
|
|
79
|
+
success: 'Broadcast updated',
|
|
80
|
+
fail: 'Failed to update broadcast',
|
|
81
|
+
},
|
|
82
|
+
sdkCall: (resend) =>
|
|
83
|
+
resend.broadcasts.update(id, {
|
|
84
|
+
...(opts.from && { from: opts.from }),
|
|
85
|
+
...(opts.subject && { subject: opts.subject }),
|
|
86
|
+
...(html && { html }),
|
|
87
|
+
...(opts.text && { text: opts.text }),
|
|
88
|
+
...(opts.name && { name: opts.name }),
|
|
89
|
+
}),
|
|
90
|
+
errorCode: 'update_error',
|
|
91
|
+
successMsg: `\nBroadcast updated: ${id}`,
|
|
92
|
+
},
|
|
93
|
+
globalOpts,
|
|
94
|
+
);
|
|
95
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { renderTable } from '../../lib/table';
|
|
2
|
+
|
|
3
|
+
export function broadcastStatusIndicator(status: string): string {
|
|
4
|
+
switch (status) {
|
|
5
|
+
case 'draft':
|
|
6
|
+
return '○ Draft';
|
|
7
|
+
case 'queued':
|
|
8
|
+
return '⏳ Queued';
|
|
9
|
+
case 'sent':
|
|
10
|
+
return '✓ Sent';
|
|
11
|
+
default:
|
|
12
|
+
return status;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function renderBroadcastsTable(
|
|
17
|
+
broadcasts: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
name: string | null;
|
|
20
|
+
status: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
}>,
|
|
23
|
+
): string {
|
|
24
|
+
const rows = broadcasts.map((b) => [
|
|
25
|
+
b.name ?? '(untitled)',
|
|
26
|
+
b.status,
|
|
27
|
+
b.created_at,
|
|
28
|
+
b.id,
|
|
29
|
+
]);
|
|
30
|
+
return renderTable(
|
|
31
|
+
['Name', 'Status', 'Created', 'ID'],
|
|
32
|
+
rows,
|
|
33
|
+
'(no broadcasts)',
|
|
34
|
+
);
|
|
35
|
+
}
|