resend-cli 1.2.0 → 1.2.2

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 (193) hide show
  1. package/.github/workflows/release.yml +35 -8
  2. package/README.md +12 -1
  3. package/biome.json +1 -1
  4. package/bun.lock +0 -3
  5. package/package.json +3 -4
  6. package/src/cli.ts +23 -5
  7. package/src/commands/auth/login.ts +10 -8
  8. package/src/commands/doctor.ts +30 -112
  9. package/src/lib/client.ts +3 -0
  10. package/src/lib/config.ts +2 -3
  11. package/src/lib/spinner.ts +17 -10
  12. package/src/lib/update-check.ts +172 -0
  13. package/tests/commands/auth/login.test.ts +3 -1
  14. package/tests/lib/config.test.ts +4 -6
  15. package/tests/lib/update-check.test.ts +169 -0
  16. package/.claude/worktrees/emails-list/.claude/settings.local.json +0 -5
  17. package/.claude/worktrees/emails-list/.github/scripts/pr-title-check.js +0 -34
  18. package/.claude/worktrees/emails-list/.github/workflows/ci.yml +0 -32
  19. package/.claude/worktrees/emails-list/.github/workflows/pr-title-check.yml +0 -13
  20. package/.claude/worktrees/emails-list/.github/workflows/release.yml +0 -93
  21. package/.claude/worktrees/emails-list/CHANGELOG.md +0 -31
  22. package/.claude/worktrees/emails-list/LICENSE +0 -21
  23. package/.claude/worktrees/emails-list/README.md +0 -424
  24. package/.claude/worktrees/emails-list/biome.json +0 -36
  25. package/.claude/worktrees/emails-list/bun.lock +0 -76
  26. package/.claude/worktrees/emails-list/bunfig.toml +0 -2
  27. package/.claude/worktrees/emails-list/install.ps1 +0 -140
  28. package/.claude/worktrees/emails-list/install.sh +0 -301
  29. package/.claude/worktrees/emails-list/package.json +0 -43
  30. package/.claude/worktrees/emails-list/renovate.json +0 -6
  31. package/.claude/worktrees/emails-list/src/cli.ts +0 -74
  32. package/.claude/worktrees/emails-list/src/commands/api-keys/create.ts +0 -114
  33. package/.claude/worktrees/emails-list/src/commands/api-keys/delete.ts +0 -47
  34. package/.claude/worktrees/emails-list/src/commands/api-keys/index.ts +0 -26
  35. package/.claude/worktrees/emails-list/src/commands/api-keys/list.ts +0 -35
  36. package/.claude/worktrees/emails-list/src/commands/api-keys/utils.ts +0 -8
  37. package/.claude/worktrees/emails-list/src/commands/auth/index.ts +0 -20
  38. package/.claude/worktrees/emails-list/src/commands/auth/login.ts +0 -207
  39. package/.claude/worktrees/emails-list/src/commands/auth/logout.ts +0 -105
  40. package/.claude/worktrees/emails-list/src/commands/broadcasts/create.ts +0 -196
  41. package/.claude/worktrees/emails-list/src/commands/broadcasts/delete.ts +0 -46
  42. package/.claude/worktrees/emails-list/src/commands/broadcasts/get.ts +0 -59
  43. package/.claude/worktrees/emails-list/src/commands/broadcasts/index.ts +0 -43
  44. package/.claude/worktrees/emails-list/src/commands/broadcasts/list.ts +0 -60
  45. package/.claude/worktrees/emails-list/src/commands/broadcasts/send.ts +0 -56
  46. package/.claude/worktrees/emails-list/src/commands/broadcasts/update.ts +0 -95
  47. package/.claude/worktrees/emails-list/src/commands/broadcasts/utils.ts +0 -35
  48. package/.claude/worktrees/emails-list/src/commands/contact-properties/create.ts +0 -118
  49. package/.claude/worktrees/emails-list/src/commands/contact-properties/delete.ts +0 -48
  50. package/.claude/worktrees/emails-list/src/commands/contact-properties/get.ts +0 -46
  51. package/.claude/worktrees/emails-list/src/commands/contact-properties/index.ts +0 -48
  52. package/.claude/worktrees/emails-list/src/commands/contact-properties/list.ts +0 -68
  53. package/.claude/worktrees/emails-list/src/commands/contact-properties/update.ts +0 -88
  54. package/.claude/worktrees/emails-list/src/commands/contact-properties/utils.ts +0 -17
  55. package/.claude/worktrees/emails-list/src/commands/contacts/add-segment.ts +0 -78
  56. package/.claude/worktrees/emails-list/src/commands/contacts/create.ts +0 -122
  57. package/.claude/worktrees/emails-list/src/commands/contacts/delete.ts +0 -49
  58. package/.claude/worktrees/emails-list/src/commands/contacts/get.ts +0 -53
  59. package/.claude/worktrees/emails-list/src/commands/contacts/index.ts +0 -58
  60. package/.claude/worktrees/emails-list/src/commands/contacts/list.ts +0 -57
  61. package/.claude/worktrees/emails-list/src/commands/contacts/remove-segment.ts +0 -48
  62. package/.claude/worktrees/emails-list/src/commands/contacts/segments.ts +0 -39
  63. package/.claude/worktrees/emails-list/src/commands/contacts/topics.ts +0 -45
  64. package/.claude/worktrees/emails-list/src/commands/contacts/update-topics.ts +0 -90
  65. package/.claude/worktrees/emails-list/src/commands/contacts/update.ts +0 -77
  66. package/.claude/worktrees/emails-list/src/commands/contacts/utils.ts +0 -119
  67. package/.claude/worktrees/emails-list/src/commands/doctor.ts +0 -298
  68. package/.claude/worktrees/emails-list/src/commands/domains/create.ts +0 -83
  69. package/.claude/worktrees/emails-list/src/commands/domains/delete.ts +0 -42
  70. package/.claude/worktrees/emails-list/src/commands/domains/get.ts +0 -47
  71. package/.claude/worktrees/emails-list/src/commands/domains/index.ts +0 -35
  72. package/.claude/worktrees/emails-list/src/commands/domains/list.ts +0 -53
  73. package/.claude/worktrees/emails-list/src/commands/domains/update.ts +0 -75
  74. package/.claude/worktrees/emails-list/src/commands/domains/utils.ts +0 -44
  75. package/.claude/worktrees/emails-list/src/commands/domains/verify.ts +0 -38
  76. package/.claude/worktrees/emails-list/src/commands/emails/batch.ts +0 -140
  77. package/.claude/worktrees/emails-list/src/commands/emails/index.ts +0 -28
  78. package/.claude/worktrees/emails-list/src/commands/emails/list.ts +0 -73
  79. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachment.ts +0 -55
  80. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachments.ts +0 -68
  81. package/.claude/worktrees/emails-list/src/commands/emails/receiving/get.ts +0 -58
  82. package/.claude/worktrees/emails-list/src/commands/emails/receiving/index.ts +0 -28
  83. package/.claude/worktrees/emails-list/src/commands/emails/receiving/list.ts +0 -59
  84. package/.claude/worktrees/emails-list/src/commands/emails/receiving/utils.ts +0 -38
  85. package/.claude/worktrees/emails-list/src/commands/emails/send.ts +0 -189
  86. package/.claude/worktrees/emails-list/src/commands/open.ts +0 -24
  87. package/.claude/worktrees/emails-list/src/commands/segments/create.ts +0 -50
  88. package/.claude/worktrees/emails-list/src/commands/segments/delete.ts +0 -47
  89. package/.claude/worktrees/emails-list/src/commands/segments/get.ts +0 -38
  90. package/.claude/worktrees/emails-list/src/commands/segments/index.ts +0 -36
  91. package/.claude/worktrees/emails-list/src/commands/segments/list.ts +0 -58
  92. package/.claude/worktrees/emails-list/src/commands/segments/utils.ts +0 -7
  93. package/.claude/worktrees/emails-list/src/commands/teams/index.ts +0 -10
  94. package/.claude/worktrees/emails-list/src/commands/teams/list.ts +0 -35
  95. package/.claude/worktrees/emails-list/src/commands/teams/remove.ts +0 -83
  96. package/.claude/worktrees/emails-list/src/commands/teams/switch.ts +0 -73
  97. package/.claude/worktrees/emails-list/src/commands/topics/create.ts +0 -73
  98. package/.claude/worktrees/emails-list/src/commands/topics/delete.ts +0 -47
  99. package/.claude/worktrees/emails-list/src/commands/topics/get.ts +0 -42
  100. package/.claude/worktrees/emails-list/src/commands/topics/index.ts +0 -42
  101. package/.claude/worktrees/emails-list/src/commands/topics/list.ts +0 -34
  102. package/.claude/worktrees/emails-list/src/commands/topics/update.ts +0 -59
  103. package/.claude/worktrees/emails-list/src/commands/topics/utils.ts +0 -16
  104. package/.claude/worktrees/emails-list/src/commands/webhooks/create.ts +0 -128
  105. package/.claude/worktrees/emails-list/src/commands/webhooks/delete.ts +0 -49
  106. package/.claude/worktrees/emails-list/src/commands/webhooks/get.ts +0 -42
  107. package/.claude/worktrees/emails-list/src/commands/webhooks/index.ts +0 -44
  108. package/.claude/worktrees/emails-list/src/commands/webhooks/list.ts +0 -55
  109. package/.claude/worktrees/emails-list/src/commands/webhooks/update.ts +0 -83
  110. package/.claude/worktrees/emails-list/src/commands/webhooks/utils.ts +0 -36
  111. package/.claude/worktrees/emails-list/src/commands/whoami.ts +0 -71
  112. package/.claude/worktrees/emails-list/src/lib/actions.ts +0 -157
  113. package/.claude/worktrees/emails-list/src/lib/client.ts +0 -34
  114. package/.claude/worktrees/emails-list/src/lib/config.ts +0 -211
  115. package/.claude/worktrees/emails-list/src/lib/files.ts +0 -15
  116. package/.claude/worktrees/emails-list/src/lib/help-text.ts +0 -38
  117. package/.claude/worktrees/emails-list/src/lib/output.ts +0 -54
  118. package/.claude/worktrees/emails-list/src/lib/pagination.ts +0 -36
  119. package/.claude/worktrees/emails-list/src/lib/prompts.ts +0 -149
  120. package/.claude/worktrees/emails-list/src/lib/spinner.ts +0 -93
  121. package/.claude/worktrees/emails-list/src/lib/table.ts +0 -57
  122. package/.claude/worktrees/emails-list/src/lib/tty.ts +0 -28
  123. package/.claude/worktrees/emails-list/src/lib/version.ts +0 -4
  124. package/.claude/worktrees/emails-list/tests/commands/api-keys/create.test.ts +0 -195
  125. package/.claude/worktrees/emails-list/tests/commands/api-keys/delete.test.ts +0 -156
  126. package/.claude/worktrees/emails-list/tests/commands/api-keys/list.test.ts +0 -133
  127. package/.claude/worktrees/emails-list/tests/commands/auth/login.test.ts +0 -119
  128. package/.claude/worktrees/emails-list/tests/commands/auth/logout.test.ts +0 -146
  129. package/.claude/worktrees/emails-list/tests/commands/broadcasts/create.test.ts +0 -447
  130. package/.claude/worktrees/emails-list/tests/commands/broadcasts/delete.test.ts +0 -182
  131. package/.claude/worktrees/emails-list/tests/commands/broadcasts/get.test.ts +0 -146
  132. package/.claude/worktrees/emails-list/tests/commands/broadcasts/list.test.ts +0 -196
  133. package/.claude/worktrees/emails-list/tests/commands/broadcasts/send.test.ts +0 -161
  134. package/.claude/worktrees/emails-list/tests/commands/broadcasts/update.test.ts +0 -283
  135. package/.claude/worktrees/emails-list/tests/commands/contact-properties/create.test.ts +0 -250
  136. package/.claude/worktrees/emails-list/tests/commands/contact-properties/delete.test.ts +0 -183
  137. package/.claude/worktrees/emails-list/tests/commands/contact-properties/get.test.ts +0 -144
  138. package/.claude/worktrees/emails-list/tests/commands/contact-properties/list.test.ts +0 -180
  139. package/.claude/worktrees/emails-list/tests/commands/contact-properties/update.test.ts +0 -216
  140. package/.claude/worktrees/emails-list/tests/commands/contacts/add-segment.test.ts +0 -188
  141. package/.claude/worktrees/emails-list/tests/commands/contacts/create.test.ts +0 -270
  142. package/.claude/worktrees/emails-list/tests/commands/contacts/delete.test.ts +0 -192
  143. package/.claude/worktrees/emails-list/tests/commands/contacts/get.test.ts +0 -148
  144. package/.claude/worktrees/emails-list/tests/commands/contacts/list.test.ts +0 -175
  145. package/.claude/worktrees/emails-list/tests/commands/contacts/remove-segment.test.ts +0 -166
  146. package/.claude/worktrees/emails-list/tests/commands/contacts/segments.test.ts +0 -167
  147. package/.claude/worktrees/emails-list/tests/commands/contacts/topics.test.ts +0 -163
  148. package/.claude/worktrees/emails-list/tests/commands/contacts/update-topics.test.ts +0 -247
  149. package/.claude/worktrees/emails-list/tests/commands/contacts/update.test.ts +0 -205
  150. package/.claude/worktrees/emails-list/tests/commands/doctor.test.ts +0 -165
  151. package/.claude/worktrees/emails-list/tests/commands/domains/create.test.ts +0 -192
  152. package/.claude/worktrees/emails-list/tests/commands/domains/delete.test.ts +0 -156
  153. package/.claude/worktrees/emails-list/tests/commands/domains/get.test.ts +0 -137
  154. package/.claude/worktrees/emails-list/tests/commands/domains/list.test.ts +0 -164
  155. package/.claude/worktrees/emails-list/tests/commands/domains/update.test.ts +0 -223
  156. package/.claude/worktrees/emails-list/tests/commands/domains/verify.test.ts +0 -117
  157. package/.claude/worktrees/emails-list/tests/commands/emails/batch.test.ts +0 -313
  158. package/.claude/worktrees/emails-list/tests/commands/emails/list.test.ts +0 -196
  159. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachment.test.ts +0 -140
  160. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachments.test.ts +0 -168
  161. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/get.test.ts +0 -140
  162. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/list.test.ts +0 -181
  163. package/.claude/worktrees/emails-list/tests/commands/emails/send.test.ts +0 -309
  164. package/.claude/worktrees/emails-list/tests/commands/segments/create.test.ts +0 -163
  165. package/.claude/worktrees/emails-list/tests/commands/segments/delete.test.ts +0 -182
  166. package/.claude/worktrees/emails-list/tests/commands/segments/get.test.ts +0 -137
  167. package/.claude/worktrees/emails-list/tests/commands/segments/list.test.ts +0 -173
  168. package/.claude/worktrees/emails-list/tests/commands/teams/list.test.ts +0 -63
  169. package/.claude/worktrees/emails-list/tests/commands/teams/remove.test.ts +0 -103
  170. package/.claude/worktrees/emails-list/tests/commands/teams/switch.test.ts +0 -96
  171. package/.claude/worktrees/emails-list/tests/commands/topics/create.test.ts +0 -191
  172. package/.claude/worktrees/emails-list/tests/commands/topics/delete.test.ts +0 -156
  173. package/.claude/worktrees/emails-list/tests/commands/topics/get.test.ts +0 -125
  174. package/.claude/worktrees/emails-list/tests/commands/topics/list.test.ts +0 -124
  175. package/.claude/worktrees/emails-list/tests/commands/topics/update.test.ts +0 -177
  176. package/.claude/worktrees/emails-list/tests/commands/webhooks/create.test.ts +0 -224
  177. package/.claude/worktrees/emails-list/tests/commands/webhooks/delete.test.ts +0 -156
  178. package/.claude/worktrees/emails-list/tests/commands/webhooks/get.test.ts +0 -125
  179. package/.claude/worktrees/emails-list/tests/commands/webhooks/list.test.ts +0 -177
  180. package/.claude/worktrees/emails-list/tests/commands/webhooks/update.test.ts +0 -206
  181. package/.claude/worktrees/emails-list/tests/commands/whoami.test.ts +0 -99
  182. package/.claude/worktrees/emails-list/tests/helpers.ts +0 -93
  183. package/.claude/worktrees/emails-list/tests/lib/client.test.ts +0 -71
  184. package/.claude/worktrees/emails-list/tests/lib/config.test.ts +0 -414
  185. package/.claude/worktrees/emails-list/tests/lib/files.test.ts +0 -65
  186. package/.claude/worktrees/emails-list/tests/lib/help-text.test.ts +0 -97
  187. package/.claude/worktrees/emails-list/tests/lib/output.test.ts +0 -127
  188. package/.claude/worktrees/emails-list/tests/lib/prompts.test.ts +0 -178
  189. package/.claude/worktrees/emails-list/tests/lib/spinner.test.ts +0 -146
  190. package/.claude/worktrees/emails-list/tests/lib/table.test.ts +0 -63
  191. package/.claude/worktrees/emails-list/tests/lib/tty.test.ts +0 -85
  192. package/.claude/worktrees/emails-list/tsconfig.json +0 -14
  193. package/.github/workflows/test-build-windows.yml +0 -44
@@ -1,42 +0,0 @@
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
-
6
- export const getWebhookCommand = new Command('get')
7
- .description('Retrieve a webhook endpoint configuration by ID')
8
- .argument('<id>', 'Webhook UUID')
9
- .addHelpText(
10
- 'after',
11
- buildHelpText({
12
- context: `Note: The signing_secret is not returned by the get endpoint.
13
- To rotate secrets, delete the webhook and recreate it.`,
14
- output: ` {"object":"webhook","id":"<uuid>","endpoint":"<url>","events":["<event>"],"status":"enabled|disabled","created_at":"<iso-date>","signing_secret":"<whsec_...>"}`,
15
- errorCodes: ['auth_error', 'fetch_error'],
16
- examples: [
17
- 'resend webhooks get wh_abc123',
18
- 'resend webhooks get wh_abc123 --json',
19
- ],
20
- }),
21
- )
22
- .action(async (id, _opts, cmd) => {
23
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
24
- await runGet(
25
- {
26
- spinner: {
27
- loading: 'Fetching webhook...',
28
- success: 'Webhook fetched',
29
- fail: 'Failed to fetch webhook',
30
- },
31
- sdkCall: (resend) => resend.webhooks.get(id),
32
- onInteractive: (d) => {
33
- console.log(`\n${d.endpoint}`);
34
- console.log(`ID: ${d.id}`);
35
- console.log(`Status: ${d.status}`);
36
- console.log(`Events: ${(d.events ?? []).join(', ') || '(none)'}`);
37
- console.log(`Created: ${d.created_at}`);
38
- },
39
- },
40
- globalOpts,
41
- );
42
- });
@@ -1,44 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { buildHelpText } from '../../lib/help-text';
3
- import { createWebhookCommand } from './create';
4
- import { deleteWebhookCommand } from './delete';
5
- import { getWebhookCommand } from './get';
6
- import { listWebhooksCommand } from './list';
7
- import { updateWebhookCommand } from './update';
8
-
9
- export const webhooksCommand = new Command('webhooks')
10
- .description('Manage webhook endpoints for real-time event notifications')
11
- .addHelpText(
12
- 'after',
13
- buildHelpText({
14
- context: `Webhooks let you receive real-time event notifications from Resend at an HTTPS endpoint.
15
- Payloads are signed with Svix headers for verification.
16
-
17
- As of January 2026, webhook events fire per-recipient. A batch email to 3 recipients
18
- generates 3 email.sent events. The "to" field remains an array for backward compatibility
19
- but contains one entry per event.
20
-
21
- Event categories (17 total):
22
- Email: email.sent, email.delivered, email.delivery_delayed, email.bounced,
23
- email.complained, email.opened, email.clicked, email.failed,
24
- email.scheduled, email.suppressed, email.received
25
- Contact: contact.created, contact.updated, contact.deleted
26
- Domain: domain.created, domain.updated, domain.deleted
27
-
28
- Signature verification (Svix):
29
- Each delivery includes headers: svix-id, svix-timestamp, svix-signature
30
- Verify payloads in your application using: resend.webhooks.verify({ payload, headers, webhookSecret })`,
31
- examples: [
32
- 'resend webhooks list',
33
- 'resend webhooks create --endpoint https://app.example.com/hooks/resend --events all',
34
- 'resend webhooks get wh_abc123',
35
- 'resend webhooks update wh_abc123 --status disabled',
36
- 'resend webhooks delete wh_abc123 --yes',
37
- ],
38
- }),
39
- )
40
- .addCommand(createWebhookCommand)
41
- .addCommand(getWebhookCommand)
42
- .addCommand(listWebhooksCommand, { isDefault: true })
43
- .addCommand(updateWebhookCommand)
44
- .addCommand(deleteWebhookCommand);
@@ -1,55 +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 {
6
- buildPaginationOpts,
7
- parseLimitOpt,
8
- printPaginationHint,
9
- } from '../../lib/pagination';
10
- import { renderWebhooksTable } from './utils';
11
-
12
- export const listWebhooksCommand = new Command('list')
13
- .alias('ls')
14
- .description('List all registered webhook endpoints')
15
- .option('--limit <n>', 'Maximum number of webhooks to return (1-100)', '10')
16
- .option('--after <cursor>', 'Return webhooks after this cursor (next page)')
17
- .option(
18
- '--before <cursor>',
19
- 'Return webhooks before this cursor (previous page)',
20
- )
21
- .addHelpText(
22
- 'after',
23
- buildHelpText({
24
- context: `Pagination: use --after or --before with a webhook ID as the cursor.
25
- Only one of --after or --before may be used at a time.
26
- The response includes has_more: true when additional pages exist.`,
27
- output: ` {"object":"list","data":[{"id":"<uuid>","endpoint":"<url>","events":["<event>"],"status":"enabled","created_at":"<iso-date>"}],"has_more":false}`,
28
- errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
29
- examples: [
30
- 'resend webhooks list',
31
- 'resend webhooks list --limit 25 --json',
32
- 'resend webhooks list --after wh_abc123 --json',
33
- ],
34
- }),
35
- )
36
- .action(async (opts, cmd) => {
37
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
38
- const limit = parseLimitOpt(opts.limit, globalOpts);
39
- const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
40
- await runList(
41
- {
42
- spinner: {
43
- loading: 'Fetching webhooks...',
44
- success: 'Webhooks fetched',
45
- fail: 'Failed to list webhooks',
46
- },
47
- sdkCall: (resend) => resend.webhooks.list(paginationOpts),
48
- onInteractive: (list) => {
49
- console.log(renderWebhooksTable(list.data));
50
- printPaginationHint(list);
51
- },
52
- },
53
- globalOpts,
54
- );
55
- });
@@ -1,83 +0,0 @@
1
- import { Command, Option } from '@commander-js/extra-typings';
2
- import type { WebhookEvent } 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
- import { ALL_WEBHOOK_EVENTS } from './utils';
8
-
9
- export const updateWebhookCommand = new Command('update')
10
- .description(
11
- "Update a webhook's endpoint URL, event subscriptions, or enabled status",
12
- )
13
- .argument('<id>', 'Webhook UUID')
14
- .option('--endpoint <endpoint>', 'New HTTPS URL for this webhook')
15
- .option(
16
- '--events <events...>',
17
- 'Replace the full event subscription list. Use "all" for all 17 events.',
18
- )
19
- .addOption(
20
- new Option(
21
- '--status <status>',
22
- 'Enable or disable event delivery for this webhook',
23
- ).choices(['enabled', 'disabled'] as const),
24
- )
25
- .addHelpText(
26
- 'after',
27
- buildHelpText({
28
- context: `At least one of --endpoint, --events, or --status must be provided.
29
-
30
- --events replaces the entire event list (it is not additive).
31
- Use "all" as a shorthand for all 17 event types.
32
-
33
- --status controls whether events are delivered to this endpoint:
34
- enabled Events are delivered (default on creation)
35
- disabled Events are suppressed without deleting the webhook`,
36
- output: ` {"object":"webhook","id":"<uuid>"}`,
37
- errorCodes: ['auth_error', 'no_changes', 'update_error'],
38
- examples: [
39
- 'resend webhooks update wh_abc123 --endpoint https://new-app.example.com/hooks/resend',
40
- 'resend webhooks update wh_abc123 --events email.sent email.bounced',
41
- 'resend webhooks update wh_abc123 --events all',
42
- 'resend webhooks update wh_abc123 --status disabled',
43
- 'resend webhooks update wh_abc123 --endpoint https://new-app.example.com/hooks/resend --events all --json',
44
- ],
45
- }),
46
- )
47
- .action(async (id, opts, cmd) => {
48
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
49
-
50
- if (!opts.endpoint && !opts.events?.length && !opts.status) {
51
- outputError(
52
- {
53
- message:
54
- 'Provide at least one option to update: --endpoint, --events, or --status.',
55
- code: 'no_changes',
56
- },
57
- { json: globalOpts.json },
58
- );
59
- }
60
-
61
- const selectedEvents = opts.events?.includes('all')
62
- ? ALL_WEBHOOK_EVENTS
63
- : (opts.events as WebhookEvent[] | undefined);
64
-
65
- await runWrite(
66
- {
67
- spinner: {
68
- loading: 'Updating webhook...',
69
- success: 'Webhook updated',
70
- fail: 'Failed to update webhook',
71
- },
72
- sdkCall: (resend) =>
73
- resend.webhooks.update(id, {
74
- ...(opts.endpoint && { endpoint: opts.endpoint }),
75
- ...(selectedEvents?.length && { events: selectedEvents }),
76
- ...(opts.status && { status: opts.status }),
77
- }),
78
- errorCode: 'update_error',
79
- successMsg: `Webhook updated: ${id}`,
80
- },
81
- globalOpts,
82
- );
83
- });
@@ -1,36 +0,0 @@
1
- import type { Webhook, WebhookEvent } from 'resend';
2
- import { renderTable } from '../../lib/table';
3
-
4
- export const ALL_WEBHOOK_EVENTS: WebhookEvent[] = [
5
- 'email.sent',
6
- 'email.delivered',
7
- 'email.delivery_delayed',
8
- 'email.bounced',
9
- 'email.complained',
10
- 'email.opened',
11
- 'email.clicked',
12
- 'email.failed',
13
- 'email.scheduled',
14
- 'email.suppressed',
15
- 'email.received',
16
- 'contact.created',
17
- 'contact.updated',
18
- 'contact.deleted',
19
- 'domain.created',
20
- 'domain.updated',
21
- 'domain.deleted',
22
- ];
23
-
24
- export function renderWebhooksTable(webhooks: Webhook[]): string {
25
- const rows = webhooks.map((w) => {
26
- const eventsStr = (w.events ?? []).join(', ');
27
- const events =
28
- eventsStr.length > 60 ? `${eventsStr.slice(0, 57)}...` : eventsStr;
29
- return [w.endpoint, events, w.status, w.id];
30
- });
31
- return renderTable(
32
- ['Endpoint', 'Events', 'Status', 'ID'],
33
- rows,
34
- '(no webhooks)',
35
- );
36
- }
@@ -1,71 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import type { GlobalOpts } from '../lib/client';
3
- import { maskKey, resolveApiKey, resolveTeamName } from '../lib/config';
4
- import { buildHelpText } from '../lib/help-text';
5
- import { outputError, outputResult } from '../lib/output';
6
- import { isInteractive } from '../lib/tty';
7
-
8
- export const whoamiCommand = new Command('whoami')
9
- .description('Show current authentication status')
10
- .addHelpText(
11
- 'after',
12
- buildHelpText({
13
- setup: true,
14
- context: `Local only — no network calls.
15
- Shows which team is active and where the API key comes from.`,
16
- output: ` {"authenticated":true,"team":"production","api_key":"re_...abcd","source":"config"}
17
- {"authenticated":false}`,
18
- examples: [
19
- 'resend whoami',
20
- 'resend whoami --json',
21
- 'resend whoami --team production',
22
- ],
23
- }),
24
- )
25
- .action((_opts, cmd) => {
26
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
27
- const teamName = globalOpts.team;
28
- const resolved = resolveApiKey(globalOpts.apiKey, teamName);
29
-
30
- if (!resolved) {
31
- if (globalOpts.json || !isInteractive()) {
32
- outputResult(
33
- { authenticated: false },
34
- { json: globalOpts.json, exitCode: 1 },
35
- );
36
- // outputResult with exitCode calls process.exit, but TS doesn't know
37
- return;
38
- }
39
- outputError(
40
- {
41
- message: 'Not authenticated.\nRun `resend login` to get started.',
42
- code: 'not_authenticated',
43
- },
44
- { json: false },
45
- );
46
- return;
47
- }
48
-
49
- const team = resolved.team ?? resolveTeamName(teamName);
50
-
51
- if (globalOpts.json || !isInteractive()) {
52
- outputResult(
53
- {
54
- authenticated: true,
55
- team,
56
- api_key: maskKey(resolved.key),
57
- source: resolved.source,
58
- },
59
- { json: globalOpts.json },
60
- );
61
- return;
62
- }
63
-
64
- console.log('');
65
- console.log(` Team: ${team}`);
66
- console.log(` API Key: ${maskKey(resolved.key)}`);
67
- console.log(
68
- ` Source: ${resolved.source === 'config' ? 'config file' : resolved.source === 'env' ? 'environment variable' : 'flag'}`,
69
- );
70
- console.log('');
71
- });
@@ -1,157 +0,0 @@
1
- import type { Resend } from 'resend';
2
- import type { GlobalOpts } from './client';
3
- import { requireClient } from './client';
4
- import { outputResult } from './output';
5
- import { confirmDelete } from './prompts';
6
- import { withSpinner } from './spinner';
7
- import { isInteractive } from './tty';
8
-
9
- type SdkCall<T> = (
10
- resend: Resend,
11
- ) => Promise<{ data: T | null; error: { message: string } | null }>;
12
- type SpinnerMessages = { loading: string; success: string; fail: string };
13
-
14
- /**
15
- * Shared pattern for all get commands:
16
- * requireClient → withSpinner(fetch_error) → if/else output
17
- */
18
- export async function runGet<T>(
19
- config: {
20
- spinner: SpinnerMessages;
21
- sdkCall: SdkCall<T>;
22
- onInteractive: (data: T) => void;
23
- },
24
- globalOpts: GlobalOpts,
25
- ): Promise<void> {
26
- const resend = requireClient(globalOpts);
27
- const data = await withSpinner(
28
- config.spinner,
29
- () => config.sdkCall(resend),
30
- 'fetch_error',
31
- globalOpts,
32
- );
33
- if (!globalOpts.json && isInteractive()) {
34
- config.onInteractive(data);
35
- } else {
36
- outputResult(data, { json: globalOpts.json });
37
- }
38
- }
39
-
40
- /**
41
- * Shared pattern for all delete commands:
42
- * requireClient → confirmDelete (if needed) → withSpinner → if/else output
43
- */
44
- export async function runDelete(
45
- id: string,
46
- skipConfirm: boolean,
47
- config: {
48
- confirmMessage: string;
49
- spinner: SpinnerMessages;
50
- object: string;
51
- successMsg: string;
52
- sdkCall: SdkCall<unknown>;
53
- },
54
- globalOpts: GlobalOpts,
55
- ): Promise<void> {
56
- const resend = requireClient(globalOpts);
57
- if (!skipConfirm) {
58
- await confirmDelete(id, config.confirmMessage, globalOpts);
59
- }
60
- await withSpinner(
61
- config.spinner,
62
- () => config.sdkCall(resend),
63
- 'delete_error',
64
- globalOpts,
65
- );
66
- if (!globalOpts.json && isInteractive()) {
67
- console.log(config.successMsg);
68
- } else {
69
- outputResult(
70
- { object: config.object, id, deleted: true },
71
- { json: globalOpts.json },
72
- );
73
- }
74
- }
75
-
76
- /**
77
- * Shared pattern for create commands:
78
- * requireClient → withSpinner('create_error') → if/else output
79
- */
80
- export async function runCreate<T>(
81
- config: {
82
- spinner: SpinnerMessages;
83
- sdkCall: SdkCall<T>;
84
- onInteractive: (data: T) => void;
85
- },
86
- globalOpts: GlobalOpts,
87
- ): Promise<void> {
88
- const resend = requireClient(globalOpts);
89
- const data = await withSpinner(
90
- config.spinner,
91
- () => config.sdkCall(resend),
92
- 'create_error',
93
- globalOpts,
94
- );
95
- if (!globalOpts.json && isInteractive()) {
96
- config.onInteractive(data);
97
- } else {
98
- outputResult(data, { json: globalOpts.json });
99
- }
100
- }
101
-
102
- /**
103
- * Shared pattern for write commands (update/verify/remove-segment) where
104
- * interactive output is a single status message:
105
- * requireClient → withSpinner(errorCode) → if/else output
106
- */
107
- export async function runWrite<T>(
108
- config: {
109
- spinner: SpinnerMessages;
110
- sdkCall: SdkCall<T>;
111
- errorCode: string;
112
- successMsg: string;
113
- },
114
- globalOpts: GlobalOpts,
115
- ): Promise<void> {
116
- const resend = requireClient(globalOpts);
117
- const data = await withSpinner(
118
- config.spinner,
119
- () => config.sdkCall(resend),
120
- config.errorCode,
121
- globalOpts,
122
- );
123
- if (!globalOpts.json && isInteractive()) {
124
- console.log(config.successMsg);
125
- } else {
126
- outputResult(data, { json: globalOpts.json });
127
- }
128
- }
129
-
130
- /**
131
- * Shared pattern for all list commands:
132
- * requireClient → withSpinner → if/else output
133
- *
134
- * Callers pass pagination opts (if any) via the sdkCall closure.
135
- * The onInteractive callback handles table rendering and pagination hints.
136
- */
137
- export async function runList<T>(
138
- config: {
139
- spinner: SpinnerMessages;
140
- sdkCall: SdkCall<T>;
141
- onInteractive: (result: T) => void;
142
- },
143
- globalOpts: GlobalOpts,
144
- ): Promise<void> {
145
- const resend = requireClient(globalOpts);
146
- const result = await withSpinner(
147
- config.spinner,
148
- () => config.sdkCall(resend),
149
- 'list_error',
150
- globalOpts,
151
- );
152
- if (!globalOpts.json && isInteractive()) {
153
- config.onInteractive(result);
154
- } else {
155
- outputResult(result, { json: globalOpts.json });
156
- }
157
- }
@@ -1,34 +0,0 @@
1
- import { Resend } from 'resend';
2
- import { resolveApiKey } from './config';
3
- import { errorMessage, outputError } from './output';
4
-
5
- export type GlobalOpts = {
6
- apiKey?: string;
7
- json?: boolean;
8
- quiet?: boolean;
9
- team?: string;
10
- };
11
-
12
- export function createClient(flagValue?: string, teamName?: string): Resend {
13
- const resolved = resolveApiKey(flagValue, teamName);
14
- if (!resolved) {
15
- throw new Error(
16
- 'No API key found. Set RESEND_API_KEY, use --api-key, or run: resend login',
17
- );
18
- }
19
- return new Resend(resolved.key);
20
- }
21
-
22
- export function requireClient(opts: GlobalOpts): Resend {
23
- try {
24
- return createClient(opts.apiKey, opts.team);
25
- } catch (err) {
26
- outputError(
27
- {
28
- message: errorMessage(err, 'Failed to create client'),
29
- code: 'auth_error',
30
- },
31
- { json: opts.json },
32
- );
33
- }
34
- }