resend-cli 1.0.2 → 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,298 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { Command } from '@commander-js/extra-typings';
|
|
5
|
+
import { Resend } from 'resend';
|
|
6
|
+
import type { GlobalOpts } from '../lib/client';
|
|
7
|
+
import { maskKey, resolveApiKey } from '../lib/config';
|
|
8
|
+
import { buildHelpText } from '../lib/help-text';
|
|
9
|
+
import { errorMessage, outputResult } from '../lib/output';
|
|
10
|
+
import { createSpinner } from '../lib/spinner';
|
|
11
|
+
import { isInteractive } from '../lib/tty';
|
|
12
|
+
import { PACKAGE_NAME, VERSION } from '../lib/version';
|
|
13
|
+
|
|
14
|
+
type CheckStatus = 'pass' | 'warn' | 'fail';
|
|
15
|
+
|
|
16
|
+
type CheckResult = {
|
|
17
|
+
name: string;
|
|
18
|
+
status: CheckStatus;
|
|
19
|
+
message: string;
|
|
20
|
+
detail?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const statusIcons: Record<CheckStatus, string> = {
|
|
24
|
+
pass: '\x1B[32m✔\x1B[0m',
|
|
25
|
+
warn: '\x1B[33m!\x1B[0m',
|
|
26
|
+
fail: '\x1B[31m✗\x1B[0m',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
async function checkCliVersion(): Promise<CheckResult> {
|
|
30
|
+
try {
|
|
31
|
+
const encodedName = encodeURIComponent(PACKAGE_NAME);
|
|
32
|
+
const res = await fetch(
|
|
33
|
+
`https://registry.npmjs.org/${encodedName}/latest`,
|
|
34
|
+
{
|
|
35
|
+
signal: AbortSignal.timeout(5000),
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
return {
|
|
40
|
+
name: 'CLI Version',
|
|
41
|
+
status: 'warn',
|
|
42
|
+
message: `v${VERSION} (could not check for updates)`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const data = (await res.json()) as { version?: string };
|
|
46
|
+
const latest = data.version ?? 'unknown';
|
|
47
|
+
if (latest === VERSION) {
|
|
48
|
+
return {
|
|
49
|
+
name: 'CLI Version',
|
|
50
|
+
status: 'pass',
|
|
51
|
+
message: `v${VERSION} (latest)`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
name: 'CLI Version',
|
|
56
|
+
status: 'warn',
|
|
57
|
+
message: `v${VERSION} (latest: v${latest})`,
|
|
58
|
+
detail: 'Update available',
|
|
59
|
+
};
|
|
60
|
+
} catch {
|
|
61
|
+
return {
|
|
62
|
+
name: 'CLI Version',
|
|
63
|
+
status: 'warn',
|
|
64
|
+
message: `v${VERSION} (could not check for updates)`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function checkApiKeyPresence(): CheckResult {
|
|
70
|
+
const resolved = resolveApiKey();
|
|
71
|
+
if (!resolved) {
|
|
72
|
+
return {
|
|
73
|
+
name: 'API Key',
|
|
74
|
+
status: 'fail',
|
|
75
|
+
message: 'No API key found',
|
|
76
|
+
detail: 'Run: resend login',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const teamInfo = resolved.team ? `, team: ${resolved.team}` : '';
|
|
80
|
+
return {
|
|
81
|
+
name: 'API Key',
|
|
82
|
+
status: 'pass',
|
|
83
|
+
message: `${maskKey(resolved.key)} (source: ${resolved.source}${teamInfo})`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function checkApiValidationAndDomains(): Promise<CheckResult> {
|
|
88
|
+
const resolved = resolveApiKey();
|
|
89
|
+
if (!resolved) {
|
|
90
|
+
return {
|
|
91
|
+
name: 'API Validation',
|
|
92
|
+
status: 'fail',
|
|
93
|
+
message: 'Skipped — no API key',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const resend = new Resend(resolved.key);
|
|
99
|
+
const { data, error } = await resend.domains.list();
|
|
100
|
+
|
|
101
|
+
if (error) {
|
|
102
|
+
return {
|
|
103
|
+
name: 'API Validation',
|
|
104
|
+
status: 'fail',
|
|
105
|
+
message: `API key invalid: ${error.message}`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const domains = data?.data ?? [];
|
|
110
|
+
const verified = domains.filter((d) => d.status === 'verified');
|
|
111
|
+
const pending = domains.filter((d) => d.status !== 'verified');
|
|
112
|
+
|
|
113
|
+
if (domains.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
name: 'Domains',
|
|
116
|
+
status: 'warn',
|
|
117
|
+
message: 'No domains configured',
|
|
118
|
+
detail: 'Add a domain at https://resend.com/domains',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (verified.length === 0) {
|
|
123
|
+
return {
|
|
124
|
+
name: 'Domains',
|
|
125
|
+
status: 'warn',
|
|
126
|
+
message: `${pending.length} domain(s) pending verification`,
|
|
127
|
+
detail: domains.map((d) => `${d.name} (${d.status})`).join(', '),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
name: 'Domains',
|
|
133
|
+
status: 'pass',
|
|
134
|
+
message: `${verified.length} verified, ${pending.length} pending`,
|
|
135
|
+
detail: domains.map((d) => `${d.name} (${d.status})`).join(', '),
|
|
136
|
+
};
|
|
137
|
+
} catch (err) {
|
|
138
|
+
return {
|
|
139
|
+
name: 'API Validation',
|
|
140
|
+
status: 'fail',
|
|
141
|
+
message: errorMessage(err, 'Failed to validate API key'),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function checkAgentDetection(): CheckResult {
|
|
147
|
+
const home = homedir();
|
|
148
|
+
const agents: { name: string; found: boolean }[] = [];
|
|
149
|
+
|
|
150
|
+
// OpenClaw
|
|
151
|
+
agents.push({
|
|
152
|
+
name: 'OpenClaw',
|
|
153
|
+
found: existsSync(join(home, 'clawd', 'skills')),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Cursor
|
|
157
|
+
agents.push({ name: 'Cursor', found: existsSync(join(home, '.cursor')) });
|
|
158
|
+
|
|
159
|
+
// Claude Desktop
|
|
160
|
+
const claudeConfigPaths =
|
|
161
|
+
process.platform === 'darwin'
|
|
162
|
+
? [
|
|
163
|
+
join(
|
|
164
|
+
home,
|
|
165
|
+
'Library',
|
|
166
|
+
'Application Support',
|
|
167
|
+
'Claude',
|
|
168
|
+
'claude_desktop_config.json',
|
|
169
|
+
),
|
|
170
|
+
]
|
|
171
|
+
: process.platform === 'win32'
|
|
172
|
+
? [
|
|
173
|
+
join(
|
|
174
|
+
process.env.APPDATA ?? '',
|
|
175
|
+
'Claude',
|
|
176
|
+
'claude_desktop_config.json',
|
|
177
|
+
),
|
|
178
|
+
]
|
|
179
|
+
: [join(home, '.config', 'Claude', 'claude_desktop_config.json')];
|
|
180
|
+
agents.push({
|
|
181
|
+
name: 'Claude Desktop',
|
|
182
|
+
found: claudeConfigPaths.some(existsSync),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// VS Code MCP
|
|
186
|
+
agents.push({
|
|
187
|
+
name: 'VS Code',
|
|
188
|
+
found: existsSync(join(process.cwd(), '.vscode', 'mcp.json')),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const detected = agents.filter((a) => a.found);
|
|
192
|
+
|
|
193
|
+
if (detected.length === 0) {
|
|
194
|
+
return {
|
|
195
|
+
name: 'AI Agents',
|
|
196
|
+
status: 'pass',
|
|
197
|
+
message: 'No AI agents detected',
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
name: 'AI Agents',
|
|
203
|
+
status: 'pass',
|
|
204
|
+
message: `Detected: ${detected.map((a) => a.name).join(', ')}`,
|
|
205
|
+
detail: 'Future: run `resend setup <agent>` to configure integration',
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const doctorCommand = new Command('doctor')
|
|
210
|
+
.description(
|
|
211
|
+
'Check CLI version, API key, domain status, and AI agent detection',
|
|
212
|
+
)
|
|
213
|
+
.addHelpText(
|
|
214
|
+
'after',
|
|
215
|
+
buildHelpText({
|
|
216
|
+
setup: true,
|
|
217
|
+
context: `Checks performed:
|
|
218
|
+
CLI Version Is the installed version up to date?
|
|
219
|
+
API Key Is a key present (--api-key, RESEND_API_KEY, or credentials file)?
|
|
220
|
+
API Validation Is the key valid and accepted by the Resend API?
|
|
221
|
+
AI Agents Detected: Claude Desktop, Cursor, VS Code MCP, OpenClaw`,
|
|
222
|
+
output: ` {\n "ok": true,\n "checks": [\n {"name":"CLI Version","status":"pass","message":"v0.1.0 (latest)"},\n {"name":"API Key","status":"pass","message":"re_...abcd (source: env)"},\n {"name":"Domains","status":"pass","message":"1 verified, 0 pending"},\n {"name":"AI Agents","status":"pass","message":"Detected: Claude Desktop"}\n ]\n }\n status values: "pass" | "warn" | "fail"\n Exit code 1 if any check has status "fail"`,
|
|
223
|
+
examples: ['resend doctor', 'resend doctor --json'],
|
|
224
|
+
}),
|
|
225
|
+
)
|
|
226
|
+
.action(async (_opts, cmd) => {
|
|
227
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
228
|
+
const checks: CheckResult[] = [];
|
|
229
|
+
const interactive = isInteractive() && !globalOpts.json;
|
|
230
|
+
|
|
231
|
+
if (interactive) {
|
|
232
|
+
console.log('\n Resend Doctor\n');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Check 1: CLI Version
|
|
236
|
+
let spinner = interactive
|
|
237
|
+
? createSpinner('Checking CLI version...', 'orbit')
|
|
238
|
+
: null;
|
|
239
|
+
const versionCheck = await checkCliVersion();
|
|
240
|
+
checks.push(versionCheck);
|
|
241
|
+
if (versionCheck.status === 'warn') {
|
|
242
|
+
spinner?.warn(versionCheck.message);
|
|
243
|
+
} else {
|
|
244
|
+
spinner?.stop(versionCheck.message);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Check 2: API Key
|
|
248
|
+
spinner = interactive ? createSpinner('Checking API key...', 'scan') : null;
|
|
249
|
+
const keyCheck = checkApiKeyPresence();
|
|
250
|
+
checks.push(keyCheck);
|
|
251
|
+
if (keyCheck.status === 'fail') {
|
|
252
|
+
spinner?.fail(keyCheck.message);
|
|
253
|
+
} else {
|
|
254
|
+
spinner?.stop(keyCheck.message);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Check 3: API Validation + Domains
|
|
258
|
+
spinner = interactive
|
|
259
|
+
? createSpinner('Validating API key & domains...', 'scan')
|
|
260
|
+
: null;
|
|
261
|
+
const domainCheck = await checkApiValidationAndDomains();
|
|
262
|
+
checks.push(domainCheck);
|
|
263
|
+
if (domainCheck.status === 'fail') {
|
|
264
|
+
spinner?.fail(domainCheck.message);
|
|
265
|
+
} else if (domainCheck.status === 'warn') {
|
|
266
|
+
spinner?.warn(domainCheck.message);
|
|
267
|
+
} else {
|
|
268
|
+
spinner?.stop(domainCheck.message);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Check 4: Agent Detection
|
|
272
|
+
spinner = interactive
|
|
273
|
+
? createSpinner('Detecting AI agents...', 'scan')
|
|
274
|
+
: null;
|
|
275
|
+
const agentCheck = checkAgentDetection();
|
|
276
|
+
checks.push(agentCheck);
|
|
277
|
+
spinner?.stop(agentCheck.message);
|
|
278
|
+
|
|
279
|
+
const hasFails = checks.some((c) => c.status === 'fail');
|
|
280
|
+
|
|
281
|
+
if (!globalOpts.json && isInteractive()) {
|
|
282
|
+
console.log('');
|
|
283
|
+
for (const check of checks) {
|
|
284
|
+
const icon = statusIcons[check.status];
|
|
285
|
+
console.log(` ${icon} ${check.name}: ${check.message}`);
|
|
286
|
+
if (check.detail) {
|
|
287
|
+
console.log(` ${check.detail}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
console.log('');
|
|
291
|
+
} else {
|
|
292
|
+
outputResult({ ok: !hasFails, checks }, { json: globalOpts.json });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (hasFails) {
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Command, Option } from '@commander-js/extra-typings';
|
|
2
|
+
import { runCreate } from '../../lib/actions';
|
|
3
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
4
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
5
|
+
import { requireText } from '../../lib/prompts';
|
|
6
|
+
import { renderDnsRecordsTable } from './utils';
|
|
7
|
+
|
|
8
|
+
export const createDomainCommand = new Command('create')
|
|
9
|
+
.description('Create a new domain and receive DNS records to configure')
|
|
10
|
+
.option('--name <domain>', 'Domain name (e.g. example.com)')
|
|
11
|
+
.addOption(
|
|
12
|
+
new Option('--region <region>', 'Sending region').choices([
|
|
13
|
+
'us-east-1',
|
|
14
|
+
'eu-west-1',
|
|
15
|
+
'sa-east-1',
|
|
16
|
+
'ap-northeast-1',
|
|
17
|
+
] as const),
|
|
18
|
+
)
|
|
19
|
+
.addOption(
|
|
20
|
+
new Option('--tls <mode>', 'TLS mode (default: opportunistic)').choices([
|
|
21
|
+
'opportunistic',
|
|
22
|
+
'enforced',
|
|
23
|
+
] as const),
|
|
24
|
+
)
|
|
25
|
+
.option('--sending', 'Enable sending capability (default: enabled)')
|
|
26
|
+
.option('--receiving', 'Enable receiving capability (default: disabled)')
|
|
27
|
+
.addHelpText(
|
|
28
|
+
'after',
|
|
29
|
+
buildHelpText({
|
|
30
|
+
context:
|
|
31
|
+
'Non-interactive: --name is required (no prompts when stdin/stdout is not a TTY)',
|
|
32
|
+
output:
|
|
33
|
+
' Full domain object with DNS records array to configure in your DNS provider.',
|
|
34
|
+
errorCodes: ['auth_error', 'missing_name', 'create_error'],
|
|
35
|
+
examples: [
|
|
36
|
+
'resend domains create --name example.com',
|
|
37
|
+
'resend domains create --name example.com --region eu-west-1 --tls enforced',
|
|
38
|
+
'resend domains create --name example.com --receiving --json',
|
|
39
|
+
'resend domains create --name example.com --sending --receiving --json',
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
.action(async (opts, cmd) => {
|
|
44
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
45
|
+
|
|
46
|
+
const name = await requireText(
|
|
47
|
+
opts.name,
|
|
48
|
+
{ message: 'Domain name', placeholder: 'example.com' },
|
|
49
|
+
{ message: 'Missing --name flag.', code: 'missing_name' },
|
|
50
|
+
globalOpts,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
await runCreate(
|
|
54
|
+
{
|
|
55
|
+
spinner: {
|
|
56
|
+
loading: 'Creating domain...',
|
|
57
|
+
success: 'Domain created',
|
|
58
|
+
fail: 'Failed to create domain',
|
|
59
|
+
},
|
|
60
|
+
sdkCall: (resend) =>
|
|
61
|
+
resend.domains.create({
|
|
62
|
+
name,
|
|
63
|
+
...(opts.region && { region: opts.region }),
|
|
64
|
+
...(opts.tls && { tls: opts.tls }),
|
|
65
|
+
...((opts.sending || opts.receiving) && {
|
|
66
|
+
capabilities: {
|
|
67
|
+
...(opts.sending && { sending: 'enabled' as const }),
|
|
68
|
+
...(opts.receiving && { receiving: 'enabled' as const }),
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
}),
|
|
72
|
+
onInteractive: (d) => {
|
|
73
|
+
console.log(`\nDomain created: ${d.name} (id: ${d.id})`);
|
|
74
|
+
console.log('\nDNS Records to configure:');
|
|
75
|
+
console.log(renderDnsRecordsTable(d.records, d.name));
|
|
76
|
+
console.log(
|
|
77
|
+
`\nRun \`resend domains verify ${d.id}\` after configuring DNS.`,
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
globalOpts,
|
|
82
|
+
);
|
|
83
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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 deleteDomainCommand = new Command('delete')
|
|
7
|
+
.alias('rm')
|
|
8
|
+
.description('Delete a domain')
|
|
9
|
+
.argument('<id>', 'Domain ID')
|
|
10
|
+
.option('--yes', 'Skip confirmation prompt')
|
|
11
|
+
.addHelpText(
|
|
12
|
+
'after',
|
|
13
|
+
buildHelpText({
|
|
14
|
+
context:
|
|
15
|
+
'Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.',
|
|
16
|
+
output: ' {"object":"domain","id":"<id>","deleted":true}',
|
|
17
|
+
errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
|
|
18
|
+
examples: [
|
|
19
|
+
'resend domains delete 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --yes',
|
|
20
|
+
'resend domains delete 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --yes --json',
|
|
21
|
+
],
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
.action(async (id, opts, cmd) => {
|
|
25
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
26
|
+
await runDelete(
|
|
27
|
+
id,
|
|
28
|
+
!!opts.yes,
|
|
29
|
+
{
|
|
30
|
+
confirmMessage: `Delete domain ${id}?\nThis cannot be undone.`,
|
|
31
|
+
spinner: {
|
|
32
|
+
loading: 'Deleting domain...',
|
|
33
|
+
success: 'Domain deleted',
|
|
34
|
+
fail: 'Failed to delete domain',
|
|
35
|
+
},
|
|
36
|
+
object: 'domain',
|
|
37
|
+
successMsg: 'Domain deleted.',
|
|
38
|
+
sdkCall: (resend) => resend.domains.remove(id),
|
|
39
|
+
},
|
|
40
|
+
globalOpts,
|
|
41
|
+
);
|
|
42
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { renderDnsRecordsTable, statusIndicator } from './utils';
|
|
6
|
+
|
|
7
|
+
export const getDomainCommand = new Command('get')
|
|
8
|
+
.description(
|
|
9
|
+
'Retrieve a domain with its DNS records and current verification status',
|
|
10
|
+
)
|
|
11
|
+
.argument('<id>', 'Domain ID')
|
|
12
|
+
.addHelpText(
|
|
13
|
+
'after',
|
|
14
|
+
buildHelpText({
|
|
15
|
+
output:
|
|
16
|
+
' Full domain object including records array and current status.\n\nDomain status values: not_started | pending | verified | failed | temporary_failure',
|
|
17
|
+
errorCodes: ['auth_error', 'fetch_error'],
|
|
18
|
+
examples: [
|
|
19
|
+
'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
|
|
20
|
+
'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --json',
|
|
21
|
+
],
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
.action(async (id, _opts, cmd) => {
|
|
25
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
26
|
+
await runGet(
|
|
27
|
+
{
|
|
28
|
+
spinner: {
|
|
29
|
+
loading: 'Fetching domain...',
|
|
30
|
+
success: 'Domain fetched',
|
|
31
|
+
fail: 'Failed to fetch domain',
|
|
32
|
+
},
|
|
33
|
+
sdkCall: (resend) => resend.domains.get(id),
|
|
34
|
+
onInteractive: (d) => {
|
|
35
|
+
console.log(`\n${d.name} — ${statusIndicator(d.status)}`);
|
|
36
|
+
console.log(`ID: ${d.id}`);
|
|
37
|
+
console.log(`Region: ${d.region}`);
|
|
38
|
+
console.log(`Created: ${d.created_at}`);
|
|
39
|
+
if (d.records.length > 0) {
|
|
40
|
+
console.log('\nDNS Records:');
|
|
41
|
+
console.log(renderDnsRecordsTable(d.records, d.name));
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
globalOpts,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
3
|
+
import { createDomainCommand } from './create';
|
|
4
|
+
import { deleteDomainCommand } from './delete';
|
|
5
|
+
import { getDomainCommand } from './get';
|
|
6
|
+
import { listDomainsCommand } from './list';
|
|
7
|
+
import { updateDomainCommand } from './update';
|
|
8
|
+
import { verifyDomainCommand } from './verify';
|
|
9
|
+
|
|
10
|
+
export const domainsCommand = new Command('domains')
|
|
11
|
+
.description('Manage verified sending and receiving domains')
|
|
12
|
+
.addHelpText(
|
|
13
|
+
'after',
|
|
14
|
+
buildHelpText({
|
|
15
|
+
context: `Domain lifecycle:
|
|
16
|
+
1. resend domains create --name example.com (get DNS records)
|
|
17
|
+
2. Configure DNS records at your DNS provider
|
|
18
|
+
3. resend domains verify <id> (trigger verification)
|
|
19
|
+
4. resend domains get <id> (poll until "verified")`,
|
|
20
|
+
examples: [
|
|
21
|
+
'resend domains list',
|
|
22
|
+
'resend domains create --name example.com --region us-east-1',
|
|
23
|
+
'resend domains verify 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
|
|
24
|
+
'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
|
|
25
|
+
'resend domains update <id> --tls enforced --open-tracking',
|
|
26
|
+
'resend domains delete <id> --yes',
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
.addCommand(createDomainCommand)
|
|
31
|
+
.addCommand(verifyDomainCommand)
|
|
32
|
+
.addCommand(getDomainCommand)
|
|
33
|
+
.addCommand(listDomainsCommand, { isDefault: true })
|
|
34
|
+
.addCommand(updateDomainCommand)
|
|
35
|
+
.addCommand(deleteDomainCommand);
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { renderDomainsTable } from './utils';
|
|
11
|
+
|
|
12
|
+
export const listDomainsCommand = new Command('list')
|
|
13
|
+
.alias('ls')
|
|
14
|
+
.description('List all domains')
|
|
15
|
+
.option('--limit <n>', 'Maximum number of domains to return (1-100)', '10')
|
|
16
|
+
.option('--after <cursor>', 'Return domains after this cursor (next page)')
|
|
17
|
+
.option(
|
|
18
|
+
'--before <cursor>',
|
|
19
|
+
'Return domains before this cursor (previous page)',
|
|
20
|
+
)
|
|
21
|
+
.addHelpText(
|
|
22
|
+
'after',
|
|
23
|
+
buildHelpText({
|
|
24
|
+
output:
|
|
25
|
+
' {"object":"list","data":[...],"has_more":true}\n The list response does not include DNS records — use "resend domains get <id>" for that.',
|
|
26
|
+
errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
|
|
27
|
+
examples: [
|
|
28
|
+
'resend domains list',
|
|
29
|
+
'resend domains list --limit 25 --json',
|
|
30
|
+
'resend domains list --after <cursor> --json',
|
|
31
|
+
],
|
|
32
|
+
}),
|
|
33
|
+
)
|
|
34
|
+
.action(async (opts, cmd) => {
|
|
35
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
36
|
+
const limit = parseLimitOpt(opts.limit, globalOpts);
|
|
37
|
+
const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
|
|
38
|
+
await runList(
|
|
39
|
+
{
|
|
40
|
+
spinner: {
|
|
41
|
+
loading: 'Fetching domains...',
|
|
42
|
+
success: 'Domains fetched',
|
|
43
|
+
fail: 'Failed to list domains',
|
|
44
|
+
},
|
|
45
|
+
sdkCall: (resend) => resend.domains.list(paginationOpts),
|
|
46
|
+
onInteractive: (list) => {
|
|
47
|
+
console.log(renderDomainsTable(list.data));
|
|
48
|
+
printPaginationHint(list);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
globalOpts,
|
|
52
|
+
);
|
|
53
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Command, Option } from '@commander-js/extra-typings';
|
|
2
|
+
import type { UpdateDomainsOptions } from 'resend';
|
|
3
|
+
import { runWrite } from '../../lib/actions';
|
|
4
|
+
import type { GlobalOpts } from '../../lib/client';
|
|
5
|
+
import { buildHelpText } from '../../lib/help-text';
|
|
6
|
+
import { outputError } from '../../lib/output';
|
|
7
|
+
|
|
8
|
+
export const updateDomainCommand = new Command('update')
|
|
9
|
+
.description(
|
|
10
|
+
'Update domain settings: TLS mode, open tracking, and click tracking',
|
|
11
|
+
)
|
|
12
|
+
.argument('<id>', 'Domain ID')
|
|
13
|
+
.addOption(
|
|
14
|
+
new Option('--tls <mode>', 'TLS mode').choices([
|
|
15
|
+
'opportunistic',
|
|
16
|
+
'enforced',
|
|
17
|
+
] as const),
|
|
18
|
+
)
|
|
19
|
+
.option('--open-tracking', 'Enable open tracking')
|
|
20
|
+
.option('--no-open-tracking', 'Disable open tracking')
|
|
21
|
+
.option('--click-tracking', 'Enable click tracking')
|
|
22
|
+
.option('--no-click-tracking', 'Disable click tracking')
|
|
23
|
+
.addHelpText(
|
|
24
|
+
'after',
|
|
25
|
+
buildHelpText({
|
|
26
|
+
output: ' {"object":"domain","id":"<id>"}',
|
|
27
|
+
errorCodes: ['auth_error', 'no_changes', 'update_error'],
|
|
28
|
+
examples: [
|
|
29
|
+
'resend domains update <id> --tls enforced',
|
|
30
|
+
'resend domains update <id> --open-tracking --click-tracking',
|
|
31
|
+
'resend domains update <id> --no-open-tracking --json',
|
|
32
|
+
],
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
.action(async (id, opts, cmd) => {
|
|
36
|
+
const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
|
|
37
|
+
|
|
38
|
+
const { tls, openTracking, clickTracking } = opts;
|
|
39
|
+
|
|
40
|
+
if (!tls && openTracking === undefined && clickTracking === undefined) {
|
|
41
|
+
outputError(
|
|
42
|
+
{
|
|
43
|
+
message:
|
|
44
|
+
'Provide at least one option to update: --tls, --open-tracking, or --click-tracking.',
|
|
45
|
+
code: 'no_changes',
|
|
46
|
+
},
|
|
47
|
+
{ json: globalOpts.json },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const payload: UpdateDomainsOptions = { id };
|
|
52
|
+
if (tls) {
|
|
53
|
+
payload.tls = tls;
|
|
54
|
+
}
|
|
55
|
+
if (openTracking !== undefined) {
|
|
56
|
+
payload.openTracking = openTracking;
|
|
57
|
+
}
|
|
58
|
+
if (clickTracking !== undefined) {
|
|
59
|
+
payload.clickTracking = clickTracking;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await runWrite(
|
|
63
|
+
{
|
|
64
|
+
spinner: {
|
|
65
|
+
loading: 'Updating domain...',
|
|
66
|
+
success: 'Domain updated',
|
|
67
|
+
fail: 'Failed to update domain',
|
|
68
|
+
},
|
|
69
|
+
sdkCall: (resend) => resend.domains.update(payload),
|
|
70
|
+
errorCode: 'update_error',
|
|
71
|
+
successMsg: `Domain updated: ${id}`,
|
|
72
|
+
},
|
|
73
|
+
globalOpts,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DomainRecords } from 'resend';
|
|
2
|
+
import { renderTable } from '../../lib/table';
|
|
3
|
+
|
|
4
|
+
export function renderDnsRecordsTable(
|
|
5
|
+
records: DomainRecords[],
|
|
6
|
+
domainName: string,
|
|
7
|
+
): string {
|
|
8
|
+
const rows = records.map((r) => {
|
|
9
|
+
const displayName = r.name
|
|
10
|
+
? r.name.includes('.')
|
|
11
|
+
? r.name
|
|
12
|
+
: `${r.name}.${domainName}`
|
|
13
|
+
: domainName;
|
|
14
|
+
return [r.type, displayName, r.ttl, r.value];
|
|
15
|
+
});
|
|
16
|
+
return renderTable(
|
|
17
|
+
['Type', 'Name', 'TTL', 'Value'],
|
|
18
|
+
rows,
|
|
19
|
+
'(no DNS records)',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function renderDomainsTable(
|
|
24
|
+
domains: Array<{ id: string; name: string; status: string; region: string }>,
|
|
25
|
+
): string {
|
|
26
|
+
const rows = domains.map((d) => [d.name, d.status, d.region, d.id]);
|
|
27
|
+
return renderTable(['Name', 'Status', 'Region', 'ID'], rows, '(no domains)');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function statusIndicator(status: string): string {
|
|
31
|
+
switch (status) {
|
|
32
|
+
case 'verified':
|
|
33
|
+
return '✓ Verified';
|
|
34
|
+
case 'pending':
|
|
35
|
+
return '⏳ Pending';
|
|
36
|
+
case 'not_started':
|
|
37
|
+
return '○ Not started';
|
|
38
|
+
case 'failed':
|
|
39
|
+
case 'temporary_failure':
|
|
40
|
+
return '✗ Failed';
|
|
41
|
+
default:
|
|
42
|
+
return status;
|
|
43
|
+
}
|
|
44
|
+
}
|