resend-cli 1.1.0 → 1.2.1

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 (198) hide show
  1. package/.claude/settings.local.json +1 -10
  2. package/.claude/worktrees/emails-list/.claude/settings.local.json +5 -0
  3. package/.claude/worktrees/emails-list/.github/scripts/pr-title-check.js +34 -0
  4. package/.claude/worktrees/emails-list/.github/workflows/ci.yml +32 -0
  5. package/.claude/worktrees/emails-list/.github/workflows/pr-title-check.yml +13 -0
  6. package/.claude/worktrees/emails-list/.github/workflows/release.yml +93 -0
  7. package/.claude/worktrees/emails-list/CHANGELOG.md +31 -0
  8. package/.claude/worktrees/emails-list/LICENSE +21 -0
  9. package/.claude/worktrees/emails-list/README.md +424 -0
  10. package/.claude/worktrees/emails-list/biome.json +36 -0
  11. package/.claude/worktrees/emails-list/bun.lock +76 -0
  12. package/.claude/worktrees/emails-list/bunfig.toml +2 -0
  13. package/.claude/worktrees/emails-list/install.ps1 +140 -0
  14. package/.claude/worktrees/emails-list/install.sh +301 -0
  15. package/.claude/worktrees/emails-list/package.json +43 -0
  16. package/.claude/worktrees/emails-list/renovate.json +6 -0
  17. package/.claude/worktrees/emails-list/src/cli.ts +74 -0
  18. package/.claude/worktrees/emails-list/src/commands/api-keys/create.ts +114 -0
  19. package/.claude/worktrees/emails-list/src/commands/api-keys/delete.ts +47 -0
  20. package/.claude/worktrees/emails-list/src/commands/api-keys/index.ts +26 -0
  21. package/.claude/worktrees/emails-list/src/commands/api-keys/list.ts +35 -0
  22. package/.claude/worktrees/emails-list/src/commands/api-keys/utils.ts +8 -0
  23. package/.claude/worktrees/emails-list/src/commands/auth/index.ts +20 -0
  24. package/.claude/worktrees/emails-list/src/commands/auth/login.ts +207 -0
  25. package/.claude/worktrees/emails-list/src/commands/auth/logout.ts +105 -0
  26. package/.claude/worktrees/emails-list/src/commands/broadcasts/create.ts +196 -0
  27. package/.claude/worktrees/emails-list/src/commands/broadcasts/delete.ts +46 -0
  28. package/.claude/worktrees/emails-list/src/commands/broadcasts/get.ts +59 -0
  29. package/.claude/worktrees/emails-list/src/commands/broadcasts/index.ts +43 -0
  30. package/.claude/worktrees/emails-list/src/commands/broadcasts/list.ts +60 -0
  31. package/.claude/worktrees/emails-list/src/commands/broadcasts/send.ts +56 -0
  32. package/.claude/worktrees/emails-list/src/commands/broadcasts/update.ts +95 -0
  33. package/.claude/worktrees/emails-list/src/commands/broadcasts/utils.ts +35 -0
  34. package/.claude/worktrees/emails-list/src/commands/contact-properties/create.ts +118 -0
  35. package/.claude/worktrees/emails-list/src/commands/contact-properties/delete.ts +48 -0
  36. package/.claude/worktrees/emails-list/src/commands/contact-properties/get.ts +46 -0
  37. package/.claude/worktrees/emails-list/src/commands/contact-properties/index.ts +48 -0
  38. package/.claude/worktrees/emails-list/src/commands/contact-properties/list.ts +68 -0
  39. package/.claude/worktrees/emails-list/src/commands/contact-properties/update.ts +88 -0
  40. package/.claude/worktrees/emails-list/src/commands/contact-properties/utils.ts +17 -0
  41. package/.claude/worktrees/emails-list/src/commands/contacts/add-segment.ts +78 -0
  42. package/.claude/worktrees/emails-list/src/commands/contacts/create.ts +122 -0
  43. package/.claude/worktrees/emails-list/src/commands/contacts/delete.ts +49 -0
  44. package/.claude/worktrees/emails-list/src/commands/contacts/get.ts +53 -0
  45. package/.claude/worktrees/emails-list/src/commands/contacts/index.ts +58 -0
  46. package/.claude/worktrees/emails-list/src/commands/contacts/list.ts +57 -0
  47. package/.claude/worktrees/emails-list/src/commands/contacts/remove-segment.ts +48 -0
  48. package/.claude/worktrees/emails-list/src/commands/contacts/segments.ts +39 -0
  49. package/.claude/worktrees/emails-list/src/commands/contacts/topics.ts +45 -0
  50. package/.claude/worktrees/emails-list/src/commands/contacts/update-topics.ts +90 -0
  51. package/.claude/worktrees/emails-list/src/commands/contacts/update.ts +77 -0
  52. package/.claude/worktrees/emails-list/src/commands/contacts/utils.ts +119 -0
  53. package/.claude/worktrees/emails-list/src/commands/doctor.ts +298 -0
  54. package/.claude/worktrees/emails-list/src/commands/domains/create.ts +83 -0
  55. package/.claude/worktrees/emails-list/src/commands/domains/delete.ts +42 -0
  56. package/.claude/worktrees/emails-list/src/commands/domains/get.ts +47 -0
  57. package/.claude/worktrees/emails-list/src/commands/domains/index.ts +35 -0
  58. package/.claude/worktrees/emails-list/src/commands/domains/list.ts +53 -0
  59. package/.claude/worktrees/emails-list/src/commands/domains/update.ts +75 -0
  60. package/.claude/worktrees/emails-list/src/commands/domains/utils.ts +44 -0
  61. package/.claude/worktrees/emails-list/src/commands/domains/verify.ts +38 -0
  62. package/.claude/worktrees/emails-list/src/commands/emails/batch.ts +140 -0
  63. package/.claude/worktrees/emails-list/src/commands/emails/index.ts +28 -0
  64. package/.claude/worktrees/emails-list/src/commands/emails/list.ts +73 -0
  65. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachment.ts +55 -0
  66. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachments.ts +68 -0
  67. package/.claude/worktrees/emails-list/src/commands/emails/receiving/get.ts +58 -0
  68. package/.claude/worktrees/emails-list/src/commands/emails/receiving/index.ts +28 -0
  69. package/.claude/worktrees/emails-list/src/commands/emails/receiving/list.ts +59 -0
  70. package/.claude/worktrees/emails-list/src/commands/emails/receiving/utils.ts +38 -0
  71. package/.claude/worktrees/emails-list/src/commands/emails/send.ts +189 -0
  72. package/.claude/worktrees/emails-list/src/commands/open.ts +24 -0
  73. package/.claude/worktrees/emails-list/src/commands/segments/create.ts +50 -0
  74. package/.claude/worktrees/emails-list/src/commands/segments/delete.ts +47 -0
  75. package/.claude/worktrees/emails-list/src/commands/segments/get.ts +38 -0
  76. package/.claude/worktrees/emails-list/src/commands/segments/index.ts +36 -0
  77. package/.claude/worktrees/emails-list/src/commands/segments/list.ts +58 -0
  78. package/.claude/worktrees/emails-list/src/commands/segments/utils.ts +7 -0
  79. package/.claude/worktrees/emails-list/src/commands/teams/index.ts +10 -0
  80. package/.claude/worktrees/emails-list/src/commands/teams/list.ts +35 -0
  81. package/.claude/worktrees/emails-list/src/commands/teams/remove.ts +83 -0
  82. package/.claude/worktrees/emails-list/src/commands/teams/switch.ts +73 -0
  83. package/.claude/worktrees/emails-list/src/commands/topics/create.ts +73 -0
  84. package/.claude/worktrees/emails-list/src/commands/topics/delete.ts +47 -0
  85. package/.claude/worktrees/emails-list/src/commands/topics/get.ts +42 -0
  86. package/.claude/worktrees/emails-list/src/commands/topics/index.ts +42 -0
  87. package/.claude/worktrees/emails-list/src/commands/topics/list.ts +34 -0
  88. package/.claude/worktrees/emails-list/src/commands/topics/update.ts +59 -0
  89. package/.claude/worktrees/emails-list/src/commands/topics/utils.ts +16 -0
  90. package/.claude/worktrees/emails-list/src/commands/webhooks/create.ts +128 -0
  91. package/.claude/worktrees/emails-list/src/commands/webhooks/delete.ts +49 -0
  92. package/.claude/worktrees/emails-list/src/commands/webhooks/get.ts +42 -0
  93. package/.claude/worktrees/emails-list/src/commands/webhooks/index.ts +44 -0
  94. package/.claude/worktrees/emails-list/src/commands/webhooks/list.ts +55 -0
  95. package/.claude/worktrees/emails-list/src/commands/webhooks/update.ts +83 -0
  96. package/.claude/worktrees/emails-list/src/commands/webhooks/utils.ts +36 -0
  97. package/.claude/worktrees/emails-list/src/commands/whoami.ts +71 -0
  98. package/.claude/worktrees/emails-list/src/lib/actions.ts +157 -0
  99. package/.claude/worktrees/emails-list/src/lib/client.ts +34 -0
  100. package/.claude/worktrees/emails-list/src/lib/config.ts +211 -0
  101. package/.claude/worktrees/emails-list/src/lib/files.ts +15 -0
  102. package/.claude/worktrees/emails-list/src/lib/help-text.ts +38 -0
  103. package/.claude/worktrees/emails-list/src/lib/output.ts +54 -0
  104. package/.claude/worktrees/emails-list/src/lib/pagination.ts +36 -0
  105. package/.claude/worktrees/emails-list/src/lib/prompts.ts +149 -0
  106. package/.claude/worktrees/emails-list/src/lib/spinner.ts +93 -0
  107. package/.claude/worktrees/emails-list/src/lib/table.ts +57 -0
  108. package/.claude/worktrees/emails-list/src/lib/tty.ts +28 -0
  109. package/.claude/worktrees/emails-list/src/lib/version.ts +4 -0
  110. package/.claude/worktrees/emails-list/tests/commands/api-keys/create.test.ts +195 -0
  111. package/.claude/worktrees/emails-list/tests/commands/api-keys/delete.test.ts +156 -0
  112. package/.claude/worktrees/emails-list/tests/commands/api-keys/list.test.ts +133 -0
  113. package/.claude/worktrees/emails-list/tests/commands/auth/login.test.ts +119 -0
  114. package/.claude/worktrees/emails-list/tests/commands/auth/logout.test.ts +146 -0
  115. package/.claude/worktrees/emails-list/tests/commands/broadcasts/create.test.ts +447 -0
  116. package/.claude/worktrees/emails-list/tests/commands/broadcasts/delete.test.ts +182 -0
  117. package/.claude/worktrees/emails-list/tests/commands/broadcasts/get.test.ts +146 -0
  118. package/.claude/worktrees/emails-list/tests/commands/broadcasts/list.test.ts +196 -0
  119. package/.claude/worktrees/emails-list/tests/commands/broadcasts/send.test.ts +161 -0
  120. package/.claude/worktrees/emails-list/tests/commands/broadcasts/update.test.ts +283 -0
  121. package/.claude/worktrees/emails-list/tests/commands/contact-properties/create.test.ts +250 -0
  122. package/.claude/worktrees/emails-list/tests/commands/contact-properties/delete.test.ts +183 -0
  123. package/.claude/worktrees/emails-list/tests/commands/contact-properties/get.test.ts +144 -0
  124. package/.claude/worktrees/emails-list/tests/commands/contact-properties/list.test.ts +180 -0
  125. package/.claude/worktrees/emails-list/tests/commands/contact-properties/update.test.ts +216 -0
  126. package/.claude/worktrees/emails-list/tests/commands/contacts/add-segment.test.ts +188 -0
  127. package/.claude/worktrees/emails-list/tests/commands/contacts/create.test.ts +270 -0
  128. package/.claude/worktrees/emails-list/tests/commands/contacts/delete.test.ts +192 -0
  129. package/.claude/worktrees/emails-list/tests/commands/contacts/get.test.ts +148 -0
  130. package/.claude/worktrees/emails-list/tests/commands/contacts/list.test.ts +175 -0
  131. package/.claude/worktrees/emails-list/tests/commands/contacts/remove-segment.test.ts +166 -0
  132. package/.claude/worktrees/emails-list/tests/commands/contacts/segments.test.ts +167 -0
  133. package/.claude/worktrees/emails-list/tests/commands/contacts/topics.test.ts +163 -0
  134. package/.claude/worktrees/emails-list/tests/commands/contacts/update-topics.test.ts +247 -0
  135. package/.claude/worktrees/emails-list/tests/commands/contacts/update.test.ts +205 -0
  136. package/.claude/worktrees/emails-list/tests/commands/doctor.test.ts +165 -0
  137. package/.claude/worktrees/emails-list/tests/commands/domains/create.test.ts +192 -0
  138. package/.claude/worktrees/emails-list/tests/commands/domains/delete.test.ts +156 -0
  139. package/.claude/worktrees/emails-list/tests/commands/domains/get.test.ts +137 -0
  140. package/.claude/worktrees/emails-list/tests/commands/domains/list.test.ts +164 -0
  141. package/.claude/worktrees/emails-list/tests/commands/domains/update.test.ts +223 -0
  142. package/.claude/worktrees/emails-list/tests/commands/domains/verify.test.ts +117 -0
  143. package/.claude/worktrees/emails-list/tests/commands/emails/batch.test.ts +313 -0
  144. package/.claude/worktrees/emails-list/tests/commands/emails/list.test.ts +196 -0
  145. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachment.test.ts +140 -0
  146. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachments.test.ts +168 -0
  147. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/get.test.ts +140 -0
  148. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/list.test.ts +181 -0
  149. package/.claude/worktrees/emails-list/tests/commands/emails/send.test.ts +309 -0
  150. package/.claude/worktrees/emails-list/tests/commands/segments/create.test.ts +163 -0
  151. package/.claude/worktrees/emails-list/tests/commands/segments/delete.test.ts +182 -0
  152. package/.claude/worktrees/emails-list/tests/commands/segments/get.test.ts +137 -0
  153. package/.claude/worktrees/emails-list/tests/commands/segments/list.test.ts +173 -0
  154. package/.claude/worktrees/emails-list/tests/commands/teams/list.test.ts +63 -0
  155. package/.claude/worktrees/emails-list/tests/commands/teams/remove.test.ts +103 -0
  156. package/.claude/worktrees/emails-list/tests/commands/teams/switch.test.ts +96 -0
  157. package/.claude/worktrees/emails-list/tests/commands/topics/create.test.ts +191 -0
  158. package/.claude/worktrees/emails-list/tests/commands/topics/delete.test.ts +156 -0
  159. package/.claude/worktrees/emails-list/tests/commands/topics/get.test.ts +125 -0
  160. package/.claude/worktrees/emails-list/tests/commands/topics/list.test.ts +124 -0
  161. package/.claude/worktrees/emails-list/tests/commands/topics/update.test.ts +177 -0
  162. package/.claude/worktrees/emails-list/tests/commands/webhooks/create.test.ts +224 -0
  163. package/.claude/worktrees/emails-list/tests/commands/webhooks/delete.test.ts +156 -0
  164. package/.claude/worktrees/emails-list/tests/commands/webhooks/get.test.ts +125 -0
  165. package/.claude/worktrees/emails-list/tests/commands/webhooks/list.test.ts +177 -0
  166. package/.claude/worktrees/emails-list/tests/commands/webhooks/update.test.ts +206 -0
  167. package/.claude/worktrees/emails-list/tests/commands/whoami.test.ts +99 -0
  168. package/.claude/worktrees/emails-list/tests/helpers.ts +93 -0
  169. package/.claude/worktrees/emails-list/tests/lib/client.test.ts +71 -0
  170. package/.claude/worktrees/emails-list/tests/lib/config.test.ts +414 -0
  171. package/.claude/worktrees/emails-list/tests/lib/files.test.ts +65 -0
  172. package/.claude/worktrees/emails-list/tests/lib/help-text.test.ts +97 -0
  173. package/.claude/worktrees/emails-list/tests/lib/output.test.ts +127 -0
  174. package/.claude/worktrees/emails-list/tests/lib/prompts.test.ts +178 -0
  175. package/.claude/worktrees/emails-list/tests/lib/spinner.test.ts +146 -0
  176. package/.claude/worktrees/emails-list/tests/lib/table.test.ts +63 -0
  177. package/.claude/worktrees/emails-list/tests/lib/tty.test.ts +85 -0
  178. package/.claude/worktrees/emails-list/tsconfig.json +14 -0
  179. package/.github/workflows/ci.yml +3 -3
  180. package/.github/workflows/pr-title-check.yml +1 -1
  181. package/.github/workflows/release.yml +37 -10
  182. package/.github/workflows/test-install-windows.yml +48 -0
  183. package/README.md +20 -1
  184. package/docs/agent-dx-gaps.md +167 -0
  185. package/docs/missing-commands.md +58 -0
  186. package/docs/production-readiness.md +99 -0
  187. package/docs/secure-key-storage.md +174 -0
  188. package/install.ps1 +1 -0
  189. package/install.sh +11 -4
  190. package/package.json +2 -2
  191. package/renovate.json +4 -0
  192. package/src/cli.ts +21 -4
  193. package/src/commands/auth/login.ts +6 -10
  194. package/src/commands/open.ts +24 -0
  195. package/src/lib/client.ts +9 -1
  196. package/src/lib/help-text.ts +4 -2
  197. package/src/lib/spinner.ts +7 -3
  198. package/tests/lib/help-text.test.ts +2 -1
@@ -0,0 +1,74 @@
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 { PACKAGE_NAME, VERSION } from './lib/version';
19
+
20
+ const program = new Command()
21
+ .name('resend')
22
+ .description('Resend CLI — email for developers')
23
+ .version(
24
+ `${PACKAGE_NAME} v${VERSION}`,
25
+ '-v, --version',
26
+ 'Output the current version',
27
+ )
28
+ .option('--api-key <key>', 'Resend API key (overrides env/config)')
29
+ .option('--team <name>', 'Team profile to use (overrides RESEND_TEAM)')
30
+ .option('--json', 'Force JSON output')
31
+ .option('-q, --quiet', 'Suppress spinners and status output (implies --json)')
32
+ .configureHelp({ showGlobalOptions: true })
33
+ .hook('preAction', (thisCommand, actionCommand) => {
34
+ if (actionCommand.optsWithGlobals().quiet) {
35
+ thisCommand.setOptionValue('json', true);
36
+ }
37
+ })
38
+ .addHelpText(
39
+ 'after',
40
+ `
41
+ Environment:
42
+ RESEND_API_KEY API key — checked after --api-key, before stored credentials
43
+ Priority: --api-key flag > RESEND_API_KEY > ~/.config/resend/credentials.json
44
+ RESEND_TEAM Team profile — checked after --team flag, before active_team in config
45
+ Priority: --team flag > RESEND_TEAM > active_team in config > "default"
46
+
47
+ Output:
48
+ Human-readable by default. Pass --json or pipe stdout for machine-readable JSON.
49
+ Use --quiet (-q) in CI to suppress spinners and status messages (implies --json).
50
+ Errors always exit with code 1: {"error":{"message":"...","code":"..."}}
51
+
52
+ Examples:
53
+ $ resend login --key re_123456789
54
+ $ resend emails send --from you@domain.com --to user@example.com --subject "Hi" --text "Hello"
55
+ $ resend emails batch --file ./emails.json --json
56
+ $ resend doctor --json`,
57
+ )
58
+ .addCommand(loginCommand)
59
+ .addCommand(logoutCommand)
60
+ .addCommand(emailsCommand)
61
+ .addCommand(domainsCommand)
62
+ .addCommand(apiKeysCommand)
63
+ .addCommand(broadcastsCommand)
64
+ .addCommand(contactsCommand)
65
+ .addCommand(contactPropertiesCommand)
66
+ .addCommand(segmentsCommand)
67
+ .addCommand(topicsCommand)
68
+ .addCommand(webhooksCommand)
69
+ .addCommand(doctorCommand)
70
+ .addCommand(teamsCommand)
71
+ .addCommand(openCommand)
72
+ .addCommand(whoamiCommand);
73
+
74
+ program.parse();
@@ -0,0 +1,114 @@
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
+ });
@@ -0,0 +1,47 @@
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
+ });
@@ -0,0 +1,26 @@
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);
@@ -0,0 +1,35 @@
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
+ });
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,20 @@
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);
@@ -0,0 +1,207 @@
1
+ import { execFile } from 'node:child_process';
2
+ import * as p from '@clack/prompts';
3
+ import { Command } from '@commander-js/extra-typings';
4
+ import { Resend } from 'resend';
5
+ import type { GlobalOpts } from '../../lib/client';
6
+ import { listTeams, resolveApiKey, storeApiKey } from '../../lib/config';
7
+ import { buildHelpText } from '../../lib/help-text';
8
+ import { errorMessage, outputError, outputResult } from '../../lib/output';
9
+ import { cancelAndExit } from '../../lib/prompts';
10
+ import { createSpinner } from '../../lib/spinner';
11
+ import { isInteractive } from '../../lib/tty';
12
+
13
+ const RESEND_API_KEYS_URL = 'https://resend.com/api-keys?new=true';
14
+
15
+ function openInBrowser(url: string): Promise<boolean> {
16
+ return new Promise((resolve) => {
17
+ // `start` on Windows is a shell built-in, not an executable.
18
+ // Must invoke via `cmd.exe /c start <url>`.
19
+ const cmd =
20
+ process.platform === 'win32'
21
+ ? 'cmd.exe'
22
+ : process.platform === 'darwin'
23
+ ? 'open'
24
+ : 'xdg-open';
25
+ const args =
26
+ process.platform === 'win32' ? ['/c', 'start', '""', url] : [url];
27
+ execFile(cmd, args, { timeout: 5000 }, (err) => resolve(!err));
28
+ });
29
+ }
30
+
31
+ export const loginCommand = new Command('login')
32
+ .description('Save a Resend API key to the local credentials file')
33
+ .option('--key <key>', 'API key to store (required in non-interactive mode)')
34
+ .addHelpText(
35
+ 'after',
36
+ buildHelpText({
37
+ setup: true,
38
+ context:
39
+ 'Non-interactive: --key is required (no prompts will appear when stdin/stdout is not a TTY).',
40
+ output: ` {"success":true,"config_path":"<path>"}`,
41
+ errorCodes: ['missing_key', 'invalid_key_format', 'validation_failed'],
42
+ examples: [
43
+ 'resend login --key re_123456789',
44
+ 'resend login (interactive — prompts and opens browser)',
45
+ 'RESEND_API_KEY=re_123 resend emails send ... (skip login; use env var directly)',
46
+ ],
47
+ }),
48
+ )
49
+ .action(async (opts, cmd) => {
50
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
51
+ let apiKey = opts.key;
52
+
53
+ if (!apiKey) {
54
+ if (!isInteractive()) {
55
+ outputError(
56
+ {
57
+ message:
58
+ 'Missing --key flag. Provide your API key in non-interactive mode.',
59
+ code: 'missing_key',
60
+ },
61
+ { json: globalOpts.json },
62
+ );
63
+ }
64
+
65
+ p.intro('Resend Authentication');
66
+
67
+ const existing = resolveApiKey();
68
+ if (existing) {
69
+ p.log.info(
70
+ `Existing API key found (source: ${existing.source}). Enter a new key to replace it.`,
71
+ );
72
+ }
73
+
74
+ const method = await p.select({
75
+ message: 'How would you like to get your API key?',
76
+ options: [
77
+ {
78
+ value: 'browser' as const,
79
+ label: 'Open resend.com/api-keys in browser',
80
+ },
81
+ { value: 'manual' as const, label: 'Enter API key manually' },
82
+ ],
83
+ });
84
+
85
+ if (p.isCancel(method)) {
86
+ cancelAndExit('Login cancelled.');
87
+ }
88
+
89
+ if (method === 'browser') {
90
+ const opened = await openInBrowser(RESEND_API_KEYS_URL);
91
+ if (opened) {
92
+ p.log.info(`Opened ${RESEND_API_KEYS_URL}`);
93
+ } else {
94
+ p.log.warn(
95
+ `Could not open browser. Visit ${RESEND_API_KEYS_URL} manually.`,
96
+ );
97
+ }
98
+ }
99
+
100
+ const result = await p.password({
101
+ message: 'Enter your Resend API key:',
102
+ validate: (value) => {
103
+ if (!value) {
104
+ return 'API key is required';
105
+ }
106
+ if (!value.startsWith('re_')) {
107
+ return 'API key must start with re_';
108
+ }
109
+ return undefined;
110
+ },
111
+ });
112
+
113
+ if (p.isCancel(result)) {
114
+ cancelAndExit('Login cancelled.');
115
+ }
116
+
117
+ apiKey = result;
118
+ }
119
+
120
+ if (!apiKey.startsWith('re_')) {
121
+ outputError(
122
+ {
123
+ message: 'Invalid API key format. Key must start with re_',
124
+ code: 'invalid_key_format',
125
+ },
126
+ { json: globalOpts.json },
127
+ );
128
+ }
129
+
130
+ const spinner = createSpinner(
131
+ 'Validating API key...',
132
+ 'braille',
133
+ globalOpts.quiet,
134
+ );
135
+
136
+ try {
137
+ const resend = new Resend(apiKey);
138
+ await resend.domains.list();
139
+ spinner.stop('API key is valid');
140
+ } catch (err) {
141
+ spinner.fail('API key validation failed');
142
+ outputError(
143
+ {
144
+ message: errorMessage(err, 'Failed to validate API key'),
145
+ code: 'validation_failed',
146
+ },
147
+ { json: globalOpts.json },
148
+ );
149
+ }
150
+
151
+ let teamName = globalOpts.team;
152
+
153
+ if (!teamName && isInteractive()) {
154
+ const existingTeams = listTeams();
155
+ if (existingTeams.length > 0) {
156
+ const options = [
157
+ ...existingTeams.map((t) => ({
158
+ value: t.name,
159
+ label: `${t.name} (overwrite)`,
160
+ })),
161
+ { value: '__new__' as const, label: '+ Create new team' },
162
+ ];
163
+
164
+ const choice = await p.select({
165
+ message: 'Save API key to which team?',
166
+ options,
167
+ });
168
+
169
+ if (p.isCancel(choice)) {
170
+ cancelAndExit('Login cancelled.');
171
+ }
172
+
173
+ if (choice === '__new__') {
174
+ const newName = await p.text({
175
+ message: 'Enter a name for the new team:',
176
+ validate: (v) =>
177
+ !v || v.length === 0 ? 'Team name is required' : undefined,
178
+ });
179
+ if (p.isCancel(newName)) {
180
+ cancelAndExit('Login cancelled.');
181
+ }
182
+ teamName = newName;
183
+ } else {
184
+ teamName = choice;
185
+ }
186
+ } else {
187
+ teamName = 'default';
188
+ }
189
+ }
190
+
191
+ const configPath = storeApiKey(apiKey, teamName);
192
+ const teamLabel = teamName || 'default';
193
+
194
+ if (globalOpts.json) {
195
+ outputResult(
196
+ { success: true, config_path: configPath, team: teamLabel },
197
+ { json: true },
198
+ );
199
+ } else {
200
+ const msg = `API key stored for team '${teamLabel}' at ${configPath}`;
201
+ if (isInteractive()) {
202
+ p.outro(msg);
203
+ } else {
204
+ console.log(msg);
205
+ }
206
+ }
207
+ });
@@ -0,0 +1,105 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import * as p from '@clack/prompts';
4
+ import { Command } from '@commander-js/extra-typings';
5
+ import type { GlobalOpts } from '../../lib/client';
6
+ import {
7
+ getConfigDir,
8
+ removeAllApiKeys,
9
+ removeApiKey,
10
+ resolveTeamName,
11
+ } from '../../lib/config';
12
+ import { buildHelpText } from '../../lib/help-text';
13
+ import { errorMessage, outputError, outputResult } from '../../lib/output';
14
+ import { cancelAndExit } from '../../lib/prompts';
15
+ import { isInteractive } from '../../lib/tty';
16
+
17
+ export const logoutCommand = new Command('logout')
18
+ .description(
19
+ 'Remove the saved Resend API key from the local credentials file',
20
+ )
21
+ .addHelpText(
22
+ 'after',
23
+ buildHelpText({
24
+ setup: true,
25
+ context: `Removes the saved API key from ~/.config/resend/credentials.json.
26
+ (Linux: $XDG_CONFIG_HOME/resend/credentials.json)
27
+ (Windows: %APPDATA%\\resend\\credentials.json)
28
+
29
+ When --team is specified, only that team's entry is removed.
30
+ When no team is specified, all teams are removed.
31
+
32
+ If no credentials file exists, exits cleanly with no error.`,
33
+ output: ` {"success":true,"config_path":"<path>"}`,
34
+ errorCodes: ['remove_failed'],
35
+ examples: [
36
+ 'resend logout',
37
+ 'resend logout --team staging',
38
+ 'resend logout --json',
39
+ ],
40
+ }),
41
+ )
42
+ .action(async (_opts, cmd) => {
43
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
44
+
45
+ const configPath = join(getConfigDir(), 'credentials.json');
46
+
47
+ if (!existsSync(configPath)) {
48
+ if (!globalOpts.json && isInteractive()) {
49
+ console.log('No saved credentials found. Nothing to remove.');
50
+ } else {
51
+ outputResult(
52
+ { success: true, already_logged_out: true },
53
+ { json: globalOpts.json },
54
+ );
55
+ }
56
+ return;
57
+ }
58
+
59
+ const logoutAll = !globalOpts.team;
60
+ const teamLabel = globalOpts.team || resolveTeamName();
61
+
62
+ if (!globalOpts.json && isInteractive()) {
63
+ const message = logoutAll
64
+ ? `Remove all saved API keys at ${configPath}?`
65
+ : `Remove saved API key for team '${teamLabel}'?`;
66
+
67
+ const confirmed = await p.confirm({ message });
68
+
69
+ if (p.isCancel(confirmed) || !confirmed) {
70
+ cancelAndExit('Logout cancelled.');
71
+ }
72
+ }
73
+
74
+ try {
75
+ if (logoutAll) {
76
+ removeAllApiKeys();
77
+ } else {
78
+ removeApiKey(teamLabel);
79
+ }
80
+ } catch (err) {
81
+ outputError(
82
+ {
83
+ message: errorMessage(err, 'Failed to remove credentials'),
84
+ code: 'remove_failed',
85
+ },
86
+ { json: globalOpts.json },
87
+ );
88
+ }
89
+
90
+ if (!globalOpts.json && isInteractive()) {
91
+ const msg = logoutAll
92
+ ? 'Logged out. All API keys removed.'
93
+ : `Logged out. API key removed for team '${teamLabel}'.`;
94
+ p.outro(msg);
95
+ } else {
96
+ outputResult(
97
+ {
98
+ success: true,
99
+ config_path: configPath,
100
+ team: logoutAll ? 'all' : teamLabel,
101
+ },
102
+ { json: globalOpts.json },
103
+ );
104
+ }
105
+ });