resend-cli 1.2.2 → 1.3.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.
Files changed (182) hide show
  1. package/README.md +25 -10
  2. package/dist/cli.cjs +539 -0
  3. package/package.json +31 -12
  4. package/.claude/settings.local.json +0 -5
  5. package/.github/scripts/pr-title-check.js +0 -34
  6. package/.github/workflows/ci.yml +0 -32
  7. package/.github/workflows/pr-title-check.yml +0 -13
  8. package/.github/workflows/release.yml +0 -120
  9. package/.github/workflows/test-install-windows.yml +0 -48
  10. package/CHANGELOG.md +0 -31
  11. package/biome.json +0 -36
  12. package/bun.lock +0 -73
  13. package/bunfig.toml +0 -2
  14. package/docs/agent-dx-gaps.md +0 -167
  15. package/docs/missing-commands.md +0 -58
  16. package/docs/production-readiness.md +0 -99
  17. package/docs/secure-key-storage.md +0 -174
  18. package/install.ps1 +0 -141
  19. package/install.sh +0 -301
  20. package/renovate.json +0 -4
  21. package/src/cli.ts +0 -92
  22. package/src/commands/api-keys/create.ts +0 -114
  23. package/src/commands/api-keys/delete.ts +0 -47
  24. package/src/commands/api-keys/index.ts +0 -26
  25. package/src/commands/api-keys/list.ts +0 -35
  26. package/src/commands/api-keys/utils.ts +0 -8
  27. package/src/commands/auth/index.ts +0 -20
  28. package/src/commands/auth/login.ts +0 -234
  29. package/src/commands/auth/logout.ts +0 -105
  30. package/src/commands/broadcasts/create.ts +0 -196
  31. package/src/commands/broadcasts/delete.ts +0 -46
  32. package/src/commands/broadcasts/get.ts +0 -59
  33. package/src/commands/broadcasts/index.ts +0 -43
  34. package/src/commands/broadcasts/list.ts +0 -60
  35. package/src/commands/broadcasts/send.ts +0 -56
  36. package/src/commands/broadcasts/update.ts +0 -95
  37. package/src/commands/broadcasts/utils.ts +0 -35
  38. package/src/commands/contact-properties/create.ts +0 -118
  39. package/src/commands/contact-properties/delete.ts +0 -48
  40. package/src/commands/contact-properties/get.ts +0 -46
  41. package/src/commands/contact-properties/index.ts +0 -48
  42. package/src/commands/contact-properties/list.ts +0 -68
  43. package/src/commands/contact-properties/update.ts +0 -88
  44. package/src/commands/contact-properties/utils.ts +0 -17
  45. package/src/commands/contacts/add-segment.ts +0 -78
  46. package/src/commands/contacts/create.ts +0 -122
  47. package/src/commands/contacts/delete.ts +0 -49
  48. package/src/commands/contacts/get.ts +0 -53
  49. package/src/commands/contacts/index.ts +0 -58
  50. package/src/commands/contacts/list.ts +0 -57
  51. package/src/commands/contacts/remove-segment.ts +0 -48
  52. package/src/commands/contacts/segments.ts +0 -39
  53. package/src/commands/contacts/topics.ts +0 -45
  54. package/src/commands/contacts/update-topics.ts +0 -90
  55. package/src/commands/contacts/update.ts +0 -77
  56. package/src/commands/contacts/utils.ts +0 -119
  57. package/src/commands/doctor.ts +0 -216
  58. package/src/commands/domains/create.ts +0 -83
  59. package/src/commands/domains/delete.ts +0 -42
  60. package/src/commands/domains/get.ts +0 -47
  61. package/src/commands/domains/index.ts +0 -35
  62. package/src/commands/domains/list.ts +0 -53
  63. package/src/commands/domains/update.ts +0 -75
  64. package/src/commands/domains/utils.ts +0 -44
  65. package/src/commands/domains/verify.ts +0 -38
  66. package/src/commands/emails/batch.ts +0 -140
  67. package/src/commands/emails/index.ts +0 -24
  68. package/src/commands/emails/receiving/attachment.ts +0 -55
  69. package/src/commands/emails/receiving/attachments.ts +0 -68
  70. package/src/commands/emails/receiving/get.ts +0 -58
  71. package/src/commands/emails/receiving/index.ts +0 -28
  72. package/src/commands/emails/receiving/list.ts +0 -59
  73. package/src/commands/emails/receiving/utils.ts +0 -38
  74. package/src/commands/emails/send.ts +0 -189
  75. package/src/commands/open.ts +0 -24
  76. package/src/commands/segments/create.ts +0 -50
  77. package/src/commands/segments/delete.ts +0 -47
  78. package/src/commands/segments/get.ts +0 -38
  79. package/src/commands/segments/index.ts +0 -36
  80. package/src/commands/segments/list.ts +0 -58
  81. package/src/commands/segments/utils.ts +0 -7
  82. package/src/commands/teams/index.ts +0 -10
  83. package/src/commands/teams/list.ts +0 -35
  84. package/src/commands/teams/remove.ts +0 -86
  85. package/src/commands/teams/switch.ts +0 -76
  86. package/src/commands/topics/create.ts +0 -73
  87. package/src/commands/topics/delete.ts +0 -47
  88. package/src/commands/topics/get.ts +0 -42
  89. package/src/commands/topics/index.ts +0 -42
  90. package/src/commands/topics/list.ts +0 -34
  91. package/src/commands/topics/update.ts +0 -59
  92. package/src/commands/topics/utils.ts +0 -16
  93. package/src/commands/webhooks/create.ts +0 -128
  94. package/src/commands/webhooks/delete.ts +0 -49
  95. package/src/commands/webhooks/get.ts +0 -42
  96. package/src/commands/webhooks/index.ts +0 -44
  97. package/src/commands/webhooks/list.ts +0 -55
  98. package/src/commands/webhooks/update.ts +0 -83
  99. package/src/commands/webhooks/utils.ts +0 -36
  100. package/src/commands/whoami.ts +0 -71
  101. package/src/lib/actions.ts +0 -157
  102. package/src/lib/client.ts +0 -37
  103. package/src/lib/config.ts +0 -217
  104. package/src/lib/files.ts +0 -15
  105. package/src/lib/help-text.ts +0 -38
  106. package/src/lib/output.ts +0 -54
  107. package/src/lib/pagination.ts +0 -36
  108. package/src/lib/prompts.ts +0 -149
  109. package/src/lib/spinner.ts +0 -100
  110. package/src/lib/table.ts +0 -57
  111. package/src/lib/tty.ts +0 -28
  112. package/src/lib/update-check.ts +0 -172
  113. package/src/lib/version.ts +0 -4
  114. package/tests/commands/api-keys/create.test.ts +0 -195
  115. package/tests/commands/api-keys/delete.test.ts +0 -156
  116. package/tests/commands/api-keys/list.test.ts +0 -133
  117. package/tests/commands/auth/login.test.ts +0 -156
  118. package/tests/commands/auth/logout.test.ts +0 -146
  119. package/tests/commands/broadcasts/create.test.ts +0 -447
  120. package/tests/commands/broadcasts/delete.test.ts +0 -182
  121. package/tests/commands/broadcasts/get.test.ts +0 -146
  122. package/tests/commands/broadcasts/list.test.ts +0 -196
  123. package/tests/commands/broadcasts/send.test.ts +0 -161
  124. package/tests/commands/broadcasts/update.test.ts +0 -283
  125. package/tests/commands/contact-properties/create.test.ts +0 -250
  126. package/tests/commands/contact-properties/delete.test.ts +0 -183
  127. package/tests/commands/contact-properties/get.test.ts +0 -144
  128. package/tests/commands/contact-properties/list.test.ts +0 -180
  129. package/tests/commands/contact-properties/update.test.ts +0 -216
  130. package/tests/commands/contacts/add-segment.test.ts +0 -188
  131. package/tests/commands/contacts/create.test.ts +0 -270
  132. package/tests/commands/contacts/delete.test.ts +0 -192
  133. package/tests/commands/contacts/get.test.ts +0 -148
  134. package/tests/commands/contacts/list.test.ts +0 -175
  135. package/tests/commands/contacts/remove-segment.test.ts +0 -166
  136. package/tests/commands/contacts/segments.test.ts +0 -167
  137. package/tests/commands/contacts/topics.test.ts +0 -163
  138. package/tests/commands/contacts/update-topics.test.ts +0 -247
  139. package/tests/commands/contacts/update.test.ts +0 -205
  140. package/tests/commands/doctor.test.ts +0 -165
  141. package/tests/commands/domains/create.test.ts +0 -192
  142. package/tests/commands/domains/delete.test.ts +0 -156
  143. package/tests/commands/domains/get.test.ts +0 -137
  144. package/tests/commands/domains/list.test.ts +0 -164
  145. package/tests/commands/domains/update.test.ts +0 -223
  146. package/tests/commands/domains/verify.test.ts +0 -117
  147. package/tests/commands/emails/batch.test.ts +0 -313
  148. package/tests/commands/emails/receiving/attachment.test.ts +0 -140
  149. package/tests/commands/emails/receiving/attachments.test.ts +0 -168
  150. package/tests/commands/emails/receiving/get.test.ts +0 -140
  151. package/tests/commands/emails/receiving/list.test.ts +0 -181
  152. package/tests/commands/emails/send.test.ts +0 -309
  153. package/tests/commands/segments/create.test.ts +0 -163
  154. package/tests/commands/segments/delete.test.ts +0 -182
  155. package/tests/commands/segments/get.test.ts +0 -137
  156. package/tests/commands/segments/list.test.ts +0 -173
  157. package/tests/commands/teams/list.test.ts +0 -63
  158. package/tests/commands/teams/remove.test.ts +0 -103
  159. package/tests/commands/teams/switch.test.ts +0 -96
  160. package/tests/commands/topics/create.test.ts +0 -191
  161. package/tests/commands/topics/delete.test.ts +0 -156
  162. package/tests/commands/topics/get.test.ts +0 -125
  163. package/tests/commands/topics/list.test.ts +0 -124
  164. package/tests/commands/topics/update.test.ts +0 -177
  165. package/tests/commands/webhooks/create.test.ts +0 -224
  166. package/tests/commands/webhooks/delete.test.ts +0 -156
  167. package/tests/commands/webhooks/get.test.ts +0 -125
  168. package/tests/commands/webhooks/list.test.ts +0 -177
  169. package/tests/commands/webhooks/update.test.ts +0 -206
  170. package/tests/commands/whoami.test.ts +0 -99
  171. package/tests/helpers.ts +0 -93
  172. package/tests/lib/client.test.ts +0 -71
  173. package/tests/lib/config.test.ts +0 -445
  174. package/tests/lib/files.test.ts +0 -65
  175. package/tests/lib/help-text.test.ts +0 -97
  176. package/tests/lib/output.test.ts +0 -127
  177. package/tests/lib/prompts.test.ts +0 -178
  178. package/tests/lib/spinner.test.ts +0 -146
  179. package/tests/lib/table.test.ts +0 -63
  180. package/tests/lib/tty.test.ts +0 -85
  181. package/tests/lib/update-check.test.ts +0 -169
  182. package/tsconfig.json +0 -14
package/install.sh DELETED
@@ -1,301 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Resend CLI installer
3
- #
4
- # Usage:
5
- # curl -fsSL https://resend.com/install.sh | bash
6
- # curl -fsSL https://resend.com/install.sh | bash -s v0.1.0
7
- #
8
- # Environment variables:
9
- # RESEND_INSTALL - Custom install directory (default: ~/.resend)
10
- # GITHUB_BASE - Custom GitHub base URL (default: https://github.com)
11
-
12
- # Wrap everything in a function to protect against partial download.
13
- # If the connection drops mid-transfer, bash won't execute a truncated script.
14
- main() {
15
-
16
- set -euo pipefail
17
-
18
- # ─── Colors (only when outputting to a terminal) ─────────────────────────────
19
-
20
- Color_Off='' Red='' Green='' Dim='' Bold='' Blue='' Yellow=''
21
-
22
- if [[ -t 1 ]]; then
23
- Color_Off='\033[0m'
24
- Red='\033[0;31m'
25
- Green='\033[0;32m'
26
- Yellow='\033[0;33m'
27
- Dim='\033[0;2m'
28
- Bold='\033[1m'
29
- Blue='\033[0;34m'
30
- fi
31
-
32
- # ─── Helpers ─────────────────────────────────────────────────────────────────
33
-
34
- error() {
35
- printf "%b\n" "${Red}error${Color_Off}: $*" >&2
36
- exit 1
37
- }
38
-
39
- warn() {
40
- printf "%b\n" "${Yellow}warn${Color_Off}: $*" >&2
41
- }
42
-
43
- info() {
44
- printf "%b\n" "${Dim}$*${Color_Off}"
45
- }
46
-
47
- success() {
48
- printf "%b\n" "${Green}$*${Color_Off}"
49
- }
50
-
51
- bold() {
52
- printf "%b\n" "${Bold}$*${Color_Off}"
53
- }
54
-
55
- tildify() {
56
- if [[ $1 == "$HOME"/* ]]; then
57
- echo "~${1#"$HOME"}"
58
- else
59
- echo "$1"
60
- fi
61
- }
62
-
63
- # ─── Dependency checks ──────────────────────────────────────────────────────
64
-
65
- command -v curl >/dev/null 2>&1 || error "curl is required but not found. Install it and try again."
66
- command -v tar >/dev/null 2>&1 || error "tar is required but not found. Install it and try again."
67
-
68
- # ─── OS / Architecture detection ────────────────────────────────────────────
69
-
70
- platform=$(uname -ms)
71
-
72
- case $platform in
73
- 'Darwin x86_64') target=darwin-x64 ;;
74
- 'Darwin arm64') target=darwin-arm64 ;;
75
- 'Linux aarch64') target=linux-arm64 ;;
76
- 'Linux arm64') target=linux-arm64 ;;
77
- 'Linux x86_64') target=linux-x64 ;;
78
- *)
79
- error "Unsupported platform: ${platform}.
80
-
81
- Resend CLI supports:
82
- - macOS (Apple Silicon / Intel)
83
- - Linux (x64 / arm64)
84
-
85
- For Windows, run this in PowerShell:
86
- irm https://resend.com/install.ps1 | iex"
87
- ;;
88
- esac
89
-
90
- # Detect Rosetta 2 on macOS — prefer native arm64 binary
91
- if [[ $target == "darwin-x64" ]]; then
92
- if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0) == "1" ]]; then
93
- target=darwin-arm64
94
- info " Rosetta 2 detected — installing native arm64 binary"
95
- fi
96
- fi
97
-
98
- # Detect musl (Alpine Linux) — glibc binaries won't work
99
- if [[ $target == linux-* ]]; then
100
- if ldd --version 2>&1 | grep -qi musl 2>/dev/null; then
101
- error "Alpine Linux (musl) is not currently supported.
102
-
103
- The compiled binary requires glibc. Use one of these alternatives:
104
- - npm install -g resend-cli
105
- - Run in a glibc-based container (e.g., ubuntu, debian)"
106
- fi
107
- fi
108
-
109
- # ─── Version + Download URL ─────────────────────────────────────────────────
110
-
111
- GITHUB_BASE=${GITHUB_BASE:-"https://github.com"}
112
-
113
- # Validate GITHUB_BASE is HTTPS to prevent download from arbitrary sources
114
- case "$GITHUB_BASE" in
115
- https://*) ;;
116
- *) error "GITHUB_BASE must start with https:// (got: ${GITHUB_BASE})" ;;
117
- esac
118
-
119
- REPO="${GITHUB_BASE}/resend/resend-cli"
120
-
121
- VERSION=${1:-}
122
-
123
- # Validate version format if provided
124
- if [[ -n $VERSION ]]; then
125
- # Strip leading 'v' if present, then re-add for the tag
126
- VERSION="${VERSION#v}"
127
- if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
128
- error "Invalid version format: ${VERSION}
129
-
130
- Expected: semantic version like 0.1.0 or 1.2.3-beta.1
131
- Usage: curl -fsSL https://resend.com/install.sh | bash -s v0.1.0"
132
- fi
133
- url="${REPO}/releases/download/v${VERSION}/resend-${target}.tar.gz"
134
- else
135
- url="${REPO}/releases/latest/download/resend-${target}.tar.gz"
136
- fi
137
-
138
- # ─── Install directory ──────────────────────────────────────────────────────
139
-
140
- install_dir="${RESEND_INSTALL:-$HOME/.resend}"
141
- bin_dir="${install_dir}/bin"
142
- exe="${bin_dir}/resend"
143
-
144
- mkdir -p "$bin_dir" || error "Failed to create install directory: ${bin_dir}"
145
-
146
- # ─── Download + Extract ─────────────────────────────────────────────────────
147
-
148
- echo ""
149
- bold " Installing Resend CLI..."
150
- echo ""
151
-
152
- tmpdir=$(mktemp -d) || error "Failed to create temporary directory"
153
- trap 'rm -rf "$tmpdir"' EXIT INT TERM
154
-
155
- tmpfile="${tmpdir}/resend.tar.gz"
156
-
157
- info " Downloading from ${url}"
158
- echo ""
159
-
160
- curl --fail --location --progress-bar --output "$tmpfile" "$url" ||
161
- error "Download failed.
162
-
163
- Possible causes:
164
- - No internet connection
165
- - The version does not exist: ${VERSION:-latest}
166
- - GitHub is unreachable
167
-
168
- URL: ${url}"
169
-
170
- tar -xzf "$tmpfile" -C "$bin_dir" ||
171
- error "Failed to extract archive. The download may be corrupted — try again."
172
-
173
- chmod +x "$exe" || error "Failed to make binary executable"
174
-
175
- # Strip macOS Gatekeeper quarantine flag (set automatically on curl downloads)
176
- # Without this, macOS will block the binary: "cannot be opened because Apple
177
- # cannot check it for malicious software"
178
- if [[ $(uname -s) == "Darwin" ]]; then
179
- xattr -d com.apple.quarantine "$exe" 2>/dev/null || true
180
- fi
181
-
182
- # ─── Verify installation ────────────────────────────────────────────────────
183
-
184
- installed_version=$("$exe" --version 2>/dev/null || echo "unknown")
185
-
186
- echo ""
187
- success " Resend CLI ${installed_version} installed successfully!"
188
- echo ""
189
- info " Binary: $(tildify "$exe")"
190
-
191
- # ─── PATH setup ─────────────────────────────────────────────────────────────
192
-
193
- # Check if already on PATH
194
- if command -v resend >/dev/null 2>&1; then
195
- existing=$(command -v resend)
196
- if [[ "$existing" == "$exe" ]]; then
197
- echo ""
198
- bold " Run ${Blue}resend --help${Color_Off}${Bold} to get started${Color_Off}"
199
- echo ""
200
- exit 0
201
- else
202
- warn "another 'resend' was found at ${existing}"
203
- info " The new installation at $(tildify "$exe") may be shadowed."
204
- fi
205
- fi
206
-
207
- # Check if bin_dir is already in PATH
208
- if echo "$PATH" | tr ':' '\n' | grep -qxF "${bin_dir}" 2>/dev/null; then
209
- echo ""
210
- bold " Run ${Blue}resend --help${Color_Off}${Bold} to get started${Color_Off}"
211
- echo ""
212
- exit 0
213
- fi
214
-
215
- # Determine shell config file
216
- shell_name=$(basename "${SHELL:-}")
217
- config=""
218
- shell_line=""
219
-
220
- # Build a $HOME-relative path for shell config (~ doesn't expand inside quotes)
221
- if [[ $bin_dir == "$HOME"/* ]]; then
222
- shell_bin_dir="\$HOME${bin_dir#"$HOME"}"
223
- else
224
- shell_bin_dir="$bin_dir"
225
- fi
226
-
227
- case $shell_name in
228
- zsh)
229
- config="${ZDOTDIR:-$HOME}/.zshrc"
230
- shell_line="export PATH=\"${shell_bin_dir}:\$PATH\""
231
- ;;
232
- bash)
233
- # macOS bash opens login shells — .bash_profile is loaded, not .bashrc.
234
- # Linux bash opens non-login interactive shells — .bashrc is preferred.
235
- if [[ $(uname -s) == "Darwin" ]]; then
236
- if [[ -f "$HOME/.bash_profile" ]]; then
237
- config="$HOME/.bash_profile"
238
- elif [[ -f "$HOME/.bashrc" ]]; then
239
- config="$HOME/.bashrc"
240
- else
241
- config="$HOME/.bash_profile"
242
- fi
243
- else
244
- if [[ -f "$HOME/.bashrc" ]]; then
245
- config="$HOME/.bashrc"
246
- elif [[ -f "$HOME/.bash_profile" ]]; then
247
- config="$HOME/.bash_profile"
248
- else
249
- config="$HOME/.bashrc"
250
- fi
251
- fi
252
- shell_line="export PATH=\"${shell_bin_dir}:\$PATH\""
253
- ;;
254
- fish)
255
- config="${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/resend.fish"
256
- mkdir -p "$(dirname "$config")"
257
- shell_line="fish_add_path ${shell_bin_dir}"
258
- ;;
259
- esac
260
-
261
- if [[ -n $config ]]; then
262
- # Check if PATH entry already exists (check both tildified and absolute)
263
- if [[ -f "$config" ]] && (grep -qF "$(tildify "$bin_dir")" "$config" 2>/dev/null || grep -qF "$bin_dir" "$config" 2>/dev/null); then
264
- info " PATH already configured in $(tildify "$config")"
265
- elif [[ -w "${config%/*}" ]] || [[ -w "$config" ]]; then
266
- {
267
- echo ""
268
- echo "# Resend CLI"
269
- echo "$shell_line"
270
- } >> "$config"
271
- info " Added $(tildify "$bin_dir") to \$PATH in $(tildify "$config")"
272
- echo ""
273
- info " To start using Resend CLI, run:"
274
- echo ""
275
- bold " source $(tildify "$config")"
276
- bold " resend --help"
277
- else
278
- echo ""
279
- info " Manually add to your shell config:"
280
- echo ""
281
- bold " ${shell_line}"
282
- fi
283
- else
284
- echo ""
285
- info " Add to your shell config:"
286
- echo ""
287
- bold " export PATH=\"${shell_bin_dir}:\$PATH\""
288
- fi
289
-
290
- echo ""
291
- info " Next steps:"
292
- echo ""
293
- bold " export RESEND_API_KEY=re_..."
294
- bold " resend --help"
295
- echo ""
296
-
297
- }
298
-
299
- # Run the installer — this line MUST be the last line in the file.
300
- # If the download is interrupted, bash will not execute an incomplete function.
301
- main "$@"
package/renovate.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": ["config:recommended"]
4
- }
package/src/cli.ts DELETED
@@ -1,92 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { Command } from '@commander-js/extra-typings';
3
- import { apiKeysCommand } from './commands/api-keys/index';
4
- import { loginCommand } from './commands/auth/login';
5
- import { logoutCommand } from './commands/auth/logout';
6
- import { broadcastsCommand } from './commands/broadcasts/index';
7
- import { contactPropertiesCommand } from './commands/contact-properties/index';
8
- import { contactsCommand } from './commands/contacts/index';
9
- import { doctorCommand } from './commands/doctor';
10
- import { domainsCommand } from './commands/domains/index';
11
- import { emailsCommand } from './commands/emails/index';
12
- import { openCommand } from './commands/open';
13
- import { segmentsCommand } from './commands/segments/index';
14
- import { teamsCommand } from './commands/teams/index';
15
- import { topicsCommand } from './commands/topics/index';
16
- import { webhooksCommand } from './commands/webhooks/index';
17
- import { whoamiCommand } from './commands/whoami';
18
- import { errorMessage, outputError } from './lib/output';
19
- import { checkForUpdates } from './lib/update-check';
20
- import { PACKAGE_NAME, VERSION } from './lib/version';
21
-
22
- const BANNER = `
23
- ██████╗ ███████╗███████╗███████╗███╗ ██╗██████╗
24
- ██╔══██╗██╔════╝██╔════╝██╔════╝████╗ ██║██╔══██╗
25
- ██████╔╝█████╗ ███████╗█████╗ ██╔██╗ ██║██║ ██║
26
- ██╔══██╗██╔══╝ ╚════██║██╔══╝ ██║╚██╗██║██║ ██║
27
- ██║ ██║███████╗███████║███████╗██║ ╚████║██████╔╝
28
- ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═══╝╚═════╝
29
- `;
30
-
31
- const program = new Command()
32
- .name('resend')
33
- .description('Resend CLI — email for developers')
34
- .addHelpText('beforeAll', BANNER)
35
- .version(
36
- `${PACKAGE_NAME} v${VERSION}`,
37
- '-v, --version',
38
- 'Output the current version',
39
- )
40
- .option('--api-key <key>', 'Resend API key (overrides env/config)')
41
- .option('--team <name>', 'Team profile to use (overrides RESEND_TEAM)')
42
- .option('--json', 'Force JSON output')
43
- .option('-q, --quiet', 'Suppress spinners and status output (implies --json)')
44
- .configureHelp({ showGlobalOptions: true })
45
- .hook('preAction', (thisCommand, actionCommand) => {
46
- if (actionCommand.optsWithGlobals().quiet) {
47
- thisCommand.setOptionValue('json', true);
48
- }
49
- })
50
- .addHelpText(
51
- 'after',
52
- `
53
- Environment:
54
- RESEND_API_KEY API key — checked after --api-key, before stored credentials
55
- Priority: --api-key flag > RESEND_API_KEY > ~/.config/resend/credentials.json
56
- RESEND_TEAM Team profile — checked after --team flag, before active_team in config
57
- Priority: --team flag > RESEND_TEAM > active_team in config > "default"
58
-
59
- Output:
60
- Human-readable by default. Pass --json or pipe stdout for machine-readable JSON.
61
- Use --quiet (-q) in CI to suppress spinners and status messages (implies --json).
62
- Errors always exit with code 1: {"error":{"message":"...","code":"..."}}
63
-
64
- Examples:
65
- $ resend login
66
- $ resend emails send`,
67
- )
68
- .addCommand(loginCommand)
69
- .addCommand(logoutCommand)
70
- .addCommand(emailsCommand)
71
- .addCommand(domainsCommand)
72
- .addCommand(apiKeysCommand)
73
- .addCommand(broadcastsCommand)
74
- .addCommand(contactsCommand)
75
- .addCommand(contactPropertiesCommand)
76
- .addCommand(segmentsCommand)
77
- .addCommand(topicsCommand)
78
- .addCommand(webhooksCommand)
79
- .addCommand(doctorCommand)
80
- .addCommand(teamsCommand)
81
- .addCommand(openCommand)
82
- .addCommand(whoamiCommand);
83
-
84
- program
85
- .parseAsync()
86
- .then(() => checkForUpdates().catch(() => {}))
87
- .catch((err) => {
88
- outputError({
89
- message: errorMessage(err, 'An unexpected error occurred'),
90
- code: 'unexpected_error',
91
- });
92
- });
@@ -1,114 +0,0 @@
1
- import * as p from '@clack/prompts';
2
- import { Command, Option } from '@commander-js/extra-typings';
3
- import { runCreate } from '../../lib/actions';
4
- import type { GlobalOpts } from '../../lib/client';
5
- import { buildHelpText } from '../../lib/help-text';
6
- import { outputError } from '../../lib/output';
7
- import { cancelAndExit } from '../../lib/prompts';
8
- import { isInteractive } from '../../lib/tty';
9
-
10
- export const createApiKeyCommand = new Command('create')
11
- .description(
12
- 'Create a new API key and display the token (shown once — store it immediately)',
13
- )
14
- .option('--name <name>', 'API key name (max 50 characters)')
15
- .addOption(
16
- new Option('--permission <permission>', 'Permission level').choices([
17
- 'full_access',
18
- 'sending_access',
19
- ] as const),
20
- )
21
- .option(
22
- '--domain-id <id>',
23
- 'Restrict a sending_access key to a single domain ID',
24
- )
25
- .addHelpText(
26
- 'after',
27
- buildHelpText({
28
- context: `Non-interactive: --name is required (no prompts when stdin/stdout is not a TTY).
29
-
30
- Permissions:
31
- full_access Full API access (default)
32
- sending_access Send-only access; optionally scope to a domain with --domain-id`,
33
- output: ` {"id":"<id>","token":"<token>"}
34
- The token is only returned at creation time and cannot be retrieved again.`,
35
- errorCodes: ['auth_error', 'missing_name', 'create_error'],
36
- examples: [
37
- 'resend api-keys create --name "Production"',
38
- 'resend api-keys create --name "CI Token" --permission sending_access',
39
- 'resend api-keys create --name "Domain Token" --permission sending_access --domain-id <domain-id>',
40
- 'resend api-keys create --name "Production" --json',
41
- ],
42
- }),
43
- )
44
- .action(async (opts, cmd) => {
45
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
46
-
47
- let name = opts.name;
48
- let permission = opts.permission;
49
-
50
- if (!name) {
51
- if (!isInteractive()) {
52
- outputError(
53
- { message: 'Missing --name flag.', code: 'missing_name' },
54
- { json: globalOpts.json },
55
- );
56
- }
57
-
58
- const nameResult = await p.text({
59
- message: 'Key name',
60
- placeholder: 'My API Key',
61
- validate: (v) => {
62
- if (!v) {
63
- return 'Name is required';
64
- }
65
- if (v.length > 50) {
66
- return 'Name must be 50 characters or less';
67
- }
68
- return undefined;
69
- },
70
- });
71
- if (p.isCancel(nameResult)) {
72
- cancelAndExit('Cancelled.');
73
- }
74
- name = nameResult;
75
-
76
- const permissionResult = await p.select({
77
- message: 'Permission level',
78
- options: [
79
- { value: 'full_access' as const, label: 'Full access' },
80
- { value: 'sending_access' as const, label: 'Sending access only' },
81
- ],
82
- });
83
- if (p.isCancel(permissionResult)) {
84
- cancelAndExit('Cancelled.');
85
- }
86
- permission = permissionResult;
87
- }
88
-
89
- await runCreate(
90
- {
91
- spinner: {
92
- loading: 'Creating API key...',
93
- success: 'API key created',
94
- fail: 'Failed to create API key',
95
- },
96
- sdkCall: (resend) =>
97
- resend.apiKeys.create({
98
- name,
99
- ...(permission && { permission }),
100
- ...(opts.domainId && { domain_id: opts.domainId }),
101
- }),
102
- onInteractive: (d) => {
103
- console.log('\nAPI key created!\n');
104
- console.log(` Name: ${name}`);
105
- console.log(` ID: ${d.id}`);
106
- console.log(` Token: ${d.token}`);
107
- console.log(
108
- '\n⚠ Store this token now — it cannot be retrieved again.',
109
- );
110
- },
111
- },
112
- globalOpts,
113
- );
114
- });
@@ -1,47 +0,0 @@
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 deleteApiKeyCommand = new Command('delete')
7
- .alias('rm')
8
- .description(
9
- 'Delete an API key — any services using it will immediately lose access',
10
- )
11
- .argument('<id>', 'API key ID')
12
- .option('--yes', 'Skip confirmation prompt')
13
- .addHelpText(
14
- 'after',
15
- buildHelpText({
16
- context: `Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.
17
-
18
- Warning: Deleting a key is immediate and irreversible. Any service using this key
19
- will stop authenticating instantly. The current key (used to call this command)
20
- can delete itself — the API does not prevent self-deletion.`,
21
- output: ` {"object":"api-key","id":"<id>","deleted":true}`,
22
- errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
23
- examples: [
24
- 'resend api-keys delete dacf4072-aa82-4ff3-97de-514ae3000ee0 --yes',
25
- 'resend api-keys delete dacf4072-aa82-4ff3-97de-514ae3000ee0 --yes --json',
26
- ],
27
- }),
28
- )
29
- .action(async (id, opts, cmd) => {
30
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
31
- await runDelete(
32
- id,
33
- !!opts.yes,
34
- {
35
- confirmMessage: `Delete API key ${id}?\nAny services using this key will stop working.`,
36
- spinner: {
37
- loading: 'Deleting API key...',
38
- success: 'API key deleted',
39
- fail: 'Failed to delete API key',
40
- },
41
- object: 'api-key',
42
- successMsg: 'API key deleted.',
43
- sdkCall: (resend) => resend.apiKeys.remove(id),
44
- },
45
- globalOpts,
46
- );
47
- });
@@ -1,26 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { buildHelpText } from '../../lib/help-text';
3
- import { createApiKeyCommand } from './create';
4
- import { deleteApiKeyCommand } from './delete';
5
- import { listApiKeysCommand } from './list';
6
-
7
- export const apiKeysCommand = new Command('api-keys')
8
- .description('Manage API keys for authentication')
9
- .addHelpText(
10
- 'after',
11
- buildHelpText({
12
- context: `Security notes:
13
- - Tokens are only shown at creation time and cannot be retrieved again.
14
- - Use sending_access keys with --domain-id for per-domain CI tokens.
15
- - Deleting a key is immediate — any service using it loses access instantly.`,
16
- examples: [
17
- 'resend api-keys list',
18
- 'resend api-keys create --name "Production"',
19
- 'resend api-keys create --name "CI Token" --permission sending_access --domain-id <domain-id>',
20
- 'resend api-keys delete <id> --yes',
21
- ],
22
- }),
23
- )
24
- .addCommand(createApiKeyCommand)
25
- .addCommand(listApiKeysCommand, { isDefault: true })
26
- .addCommand(deleteApiKeyCommand);
@@ -1,35 +0,0 @@
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 { renderApiKeysTable } from './utils';
6
-
7
- export const listApiKeysCommand = new Command('list')
8
- .alias('ls')
9
- .description(
10
- 'List all API keys (IDs and names — tokens are never returned by this endpoint)',
11
- )
12
- .addHelpText(
13
- 'after',
14
- buildHelpText({
15
- output: ` {"object":"list","data":[{"id":"<id>","name":"<name>","created_at":"<date>"}]}
16
- Tokens are never included in list responses.`,
17
- errorCodes: ['auth_error', 'list_error'],
18
- examples: ['resend api-keys list', 'resend api-keys list --json'],
19
- }),
20
- )
21
- .action(async (_opts, cmd) => {
22
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
23
- await runList(
24
- {
25
- spinner: {
26
- loading: 'Fetching API keys...',
27
- success: 'API keys fetched',
28
- fail: 'Failed to list API keys',
29
- },
30
- sdkCall: (resend) => resend.apiKeys.list(),
31
- onInteractive: (list) => console.log(renderApiKeysTable(list.data)),
32
- },
33
- globalOpts,
34
- );
35
- });
@@ -1,8 +0,0 @@
1
- import { renderTable } from '../../lib/table';
2
-
3
- export function renderApiKeysTable(
4
- keys: Array<{ id: string; name: string; created_at: string }>,
5
- ): string {
6
- const rows = keys.map((k) => [k.name, k.id, k.created_at]);
7
- return renderTable(['Name', 'ID', 'Created'], rows, '(no API keys)');
8
- }
@@ -1,20 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { buildHelpText } from '../../lib/help-text';
3
- import { loginCommand } from './login';
4
- import { logoutCommand } from './logout';
5
-
6
- export const authCommand = new Command('auth')
7
- .description('Manage authentication')
8
- .addHelpText(
9
- 'after',
10
- buildHelpText({
11
- setup: true,
12
- examples: [
13
- 'resend login',
14
- 'resend login --key re_123456789',
15
- 'resend logout',
16
- ],
17
- }),
18
- )
19
- .addCommand(loginCommand)
20
- .addCommand(logoutCommand);