resend-cli 1.1.0 → 1.2.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 (205) 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 +2 -2
  182. package/.github/workflows/test-build-windows.yml +44 -0
  183. package/.github/workflows/test-install-windows.yml +48 -0
  184. package/README.md +8 -0
  185. package/docs/agent-dx-gaps.md +167 -0
  186. package/docs/missing-commands.md +58 -0
  187. package/docs/production-readiness.md +99 -0
  188. package/docs/secure-key-storage.md +174 -0
  189. package/install.ps1 +1 -0
  190. package/install.sh +11 -4
  191. package/package.json +1 -1
  192. package/renovate.json +4 -0
  193. package/src/cli.ts +9 -0
  194. package/src/commands/auth/login.ts +34 -13
  195. package/src/commands/doctor.ts +3 -3
  196. package/src/commands/open.ts +24 -0
  197. package/src/commands/teams/remove.ts +5 -2
  198. package/src/commands/teams/switch.ts +3 -0
  199. package/src/lib/client.ts +6 -1
  200. package/src/lib/config.ts +37 -30
  201. package/src/lib/help-text.ts +4 -2
  202. package/src/lib/spinner.ts +7 -3
  203. package/tests/commands/auth/login.test.ts +35 -0
  204. package/tests/lib/config.test.ts +40 -7
  205. package/tests/lib/help-text.test.ts +2 -1
@@ -0,0 +1,49 @@
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 deleteContactCommand = new Command('delete')
7
+ .alias('rm')
8
+ .description('Delete a contact')
9
+ .argument(
10
+ '<id>',
11
+ 'Contact UUID or email address — both are accepted by the API',
12
+ )
13
+ .option(
14
+ '--yes',
15
+ 'Skip the confirmation prompt (required in non-interactive mode)',
16
+ )
17
+ .addHelpText(
18
+ 'after',
19
+ buildHelpText({
20
+ context: `The <id> argument accepts either a UUID or an email address.
21
+
22
+ Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.`,
23
+ output: ` {"object":"contact","id":"<id>","deleted":true}`,
24
+ errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
25
+ examples: [
26
+ 'resend contacts delete 479e3145-dd38-4932-8c0c-e58b548c9e76 --yes',
27
+ 'resend contacts delete user@example.com --yes --json',
28
+ ],
29
+ }),
30
+ )
31
+ .action(async (id, opts, cmd) => {
32
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
33
+ await runDelete(
34
+ id,
35
+ !!opts.yes,
36
+ {
37
+ confirmMessage: `Delete contact ${id}?\nThis cannot be undone.`,
38
+ spinner: {
39
+ loading: 'Deleting contact...',
40
+ success: 'Contact deleted',
41
+ fail: 'Failed to delete contact',
42
+ },
43
+ object: 'contact',
44
+ successMsg: 'Contact deleted.',
45
+ sdkCall: (resend) => resend.contacts.remove(id),
46
+ },
47
+ globalOpts,
48
+ );
49
+ });
@@ -0,0 +1,53 @@
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 getContactCommand = new Command('get')
7
+ .description('Retrieve a contact by ID or email address')
8
+ .argument(
9
+ '<id>',
10
+ 'Contact UUID or email address — both are accepted by the API',
11
+ )
12
+ .addHelpText(
13
+ 'after',
14
+ buildHelpText({
15
+ output: ` {\n "object": "contact",\n "id": "<uuid>",\n "email": "user@example.com",\n "first_name": "Jane",\n "last_name": "Smith",\n "created_at": "2026-01-01T00:00:00.000Z",\n "unsubscribed": false,\n "properties": {}\n }`,
16
+ errorCodes: ['auth_error', 'fetch_error'],
17
+ examples: [
18
+ 'resend contacts get 479e3145-dd38-4932-8c0c-e58b548c9e76',
19
+ 'resend contacts get user@example.com',
20
+ 'resend contacts get 479e3145-dd38-4932-8c0c-e58b548c9e76 --json',
21
+ ],
22
+ }),
23
+ )
24
+ .action(async (id, _opts, cmd) => {
25
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
26
+ await runGet(
27
+ {
28
+ spinner: {
29
+ loading: 'Fetching contact...',
30
+ success: 'Contact fetched',
31
+ fail: 'Failed to fetch contact',
32
+ },
33
+ sdkCall: (resend) => resend.contacts.get(id),
34
+ onInteractive: (data) => {
35
+ const name = [data.first_name, data.last_name]
36
+ .filter(Boolean)
37
+ .join(' ');
38
+ console.log(`\n${data.email}${name ? ` (${name})` : ''}`);
39
+ console.log(`ID: ${data.id}`);
40
+ console.log(`Created: ${data.created_at}`);
41
+ console.log(`Unsubscribed: ${data.unsubscribed ? 'yes' : 'no'}`);
42
+ const propEntries = Object.entries(data.properties ?? {});
43
+ if (propEntries.length > 0) {
44
+ console.log('Properties:');
45
+ for (const [key, val] of propEntries) {
46
+ console.log(` ${key}: ${val.value}`);
47
+ }
48
+ }
49
+ },
50
+ },
51
+ globalOpts,
52
+ );
53
+ });
@@ -0,0 +1,58 @@
1
+ import { Command } from '@commander-js/extra-typings';
2
+ import { buildHelpText } from '../../lib/help-text';
3
+ import { addContactSegmentCommand } from './add-segment';
4
+ import { createContactCommand } from './create';
5
+ import { deleteContactCommand } from './delete';
6
+ import { getContactCommand } from './get';
7
+ import { listContactsCommand } from './list';
8
+ import { removeContactSegmentCommand } from './remove-segment';
9
+ import { listContactSegmentsCommand } from './segments';
10
+ import { listContactTopicsCommand } from './topics';
11
+ import { updateContactCommand } from './update';
12
+ import { updateContactTopicsCommand } from './update-topics';
13
+
14
+ export const contactsCommand = new Command('contacts')
15
+ .description('Manage contacts — the global list of people you send email to')
16
+ .addHelpText(
17
+ 'after',
18
+ buildHelpText({
19
+ context: `Contacts are global entities (not audience-scoped since the 2025 migration).
20
+ Each contact is identified by a UUID or email address — both are accepted in all subcommands.
21
+
22
+ Properties:
23
+ Contacts carry custom key-value properties (e.g. plan, company) accessible in broadcast templates
24
+ via {{{PROPERTY_NAME|fallback}}} triple-brace interpolation.
25
+ firstName/lastName are convenience aliases stored as FIRST_NAME/LAST_NAME properties.
26
+
27
+ Subscription:
28
+ --unsubscribed is a team-wide opt-out from all broadcasts.
29
+ Fine-grained control is available via topic subscriptions (see "resend contacts topics").
30
+
31
+ Segments:
32
+ Contacts can belong to multiple segments. Segments determine which contacts receive a broadcast.
33
+ Manage membership with "resend contacts add-segment" and "resend contacts remove-segment".`,
34
+ examples: [
35
+ 'resend contacts list',
36
+ 'resend contacts create --email jane@example.com --first-name Jane',
37
+ 'resend contacts get 479e3145-dd38-4932-8c0c-e58b548c9e76',
38
+ 'resend contacts get user@example.com',
39
+ 'resend contacts update user@example.com --unsubscribed',
40
+ 'resend contacts delete 479e3145-dd38-4932-8c0c-e58b548c9e76 --yes',
41
+ 'resend contacts segments user@example.com',
42
+ 'resend contacts add-segment user@example.com --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
43
+ 'resend contacts remove-segment user@example.com 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
44
+ 'resend contacts topics user@example.com',
45
+ `resend contacts update-topics user@example.com --topics '[{"id":"topic-uuid","subscription":"opt_in"}]'`,
46
+ ],
47
+ }),
48
+ )
49
+ .addCommand(createContactCommand)
50
+ .addCommand(getContactCommand)
51
+ .addCommand(listContactsCommand, { isDefault: true })
52
+ .addCommand(updateContactCommand)
53
+ .addCommand(deleteContactCommand)
54
+ .addCommand(listContactSegmentsCommand)
55
+ .addCommand(addContactSegmentCommand)
56
+ .addCommand(removeContactSegmentCommand)
57
+ .addCommand(listContactTopicsCommand)
58
+ .addCommand(updateContactTopicsCommand);
@@ -0,0 +1,57 @@
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 { renderContactsTable } from './utils';
11
+
12
+ export const listContactsCommand = new Command('list')
13
+ .alias('ls')
14
+ .description('List all contacts')
15
+ .option('--limit <n>', 'Maximum number of contacts to return (1-100)', '10')
16
+ .option('--after <cursor>', 'Return contacts after this cursor (next page)')
17
+ .option(
18
+ '--before <cursor>',
19
+ 'Return contacts before this cursor (previous page)',
20
+ )
21
+ .addHelpText(
22
+ 'after',
23
+ buildHelpText({
24
+ context: `Contacts are global — they are not scoped to audiences or segments since the 2025 migration.
25
+
26
+ Pagination: use --after or --before with a contact ID as the cursor.
27
+ Only one of --after or --before may be used at a time.
28
+ The response includes has_more: true when additional pages exist.`,
29
+ output: ` {"object":"list","data":[{"id":"...","email":"...","first_name":"...","last_name":"...","unsubscribed":false}],"has_more":false}`,
30
+ errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
31
+ examples: [
32
+ 'resend contacts list',
33
+ 'resend contacts list --limit 25 --json',
34
+ 'resend contacts list --after 479e3145-dd38-4932-8c0c-e58b548c9e76 --json',
35
+ ],
36
+ }),
37
+ )
38
+ .action(async (opts, cmd) => {
39
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
40
+ const limit = parseLimitOpt(opts.limit, globalOpts);
41
+ const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
42
+ await runList(
43
+ {
44
+ spinner: {
45
+ loading: 'Fetching contacts...',
46
+ success: 'Contacts fetched',
47
+ fail: 'Failed to list contacts',
48
+ },
49
+ sdkCall: (resend) => resend.contacts.list(paginationOpts),
50
+ onInteractive: (list) => {
51
+ console.log(renderContactsTable(list.data));
52
+ printPaginationHint(list);
53
+ },
54
+ },
55
+ globalOpts,
56
+ );
57
+ });
@@ -0,0 +1,48 @@
1
+ import { Command } from '@commander-js/extra-typings';
2
+ import type { RemoveContactSegmentOptions } from 'resend';
3
+ import { runWrite } from '../../lib/actions';
4
+ import type { GlobalOpts } from '../../lib/client';
5
+ import { buildHelpText } from '../../lib/help-text';
6
+ import { segmentContactIdentifier } from './utils';
7
+
8
+ export const removeContactSegmentCommand = new Command('remove-segment')
9
+ .description('Remove a contact from a segment')
10
+ .argument('<contactId>', 'Contact UUID or email address')
11
+ .argument('<segmentId>', 'Segment ID to remove the contact from')
12
+ .addHelpText(
13
+ 'after',
14
+ buildHelpText({
15
+ context: `The <contactId> argument accepts either a UUID or an email address.
16
+ The <segmentId> argument must be a segment UUID (not an email).`,
17
+ output: ` {"id":"<segment-id>","deleted":true}`,
18
+ errorCodes: ['auth_error', 'remove_segment_error'],
19
+ examples: [
20
+ 'resend contacts remove-segment 479e3145-dd38-4932-8c0c-e58b548c9e76 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
21
+ 'resend contacts remove-segment user@example.com 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --json',
22
+ ],
23
+ }),
24
+ )
25
+ .action(async (contactId, segmentId, _opts, cmd) => {
26
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
27
+
28
+ // segmentContactIdentifier resolves UUID vs email for the ContactSegmentsBaseOptions
29
+ // discriminated union. The spread of that union requires an explicit cast.
30
+ const payload = {
31
+ ...segmentContactIdentifier(contactId),
32
+ segmentId,
33
+ } as RemoveContactSegmentOptions;
34
+
35
+ await runWrite(
36
+ {
37
+ spinner: {
38
+ loading: 'Removing contact from segment...',
39
+ success: 'Contact removed from segment',
40
+ fail: 'Failed to remove contact from segment',
41
+ },
42
+ sdkCall: (resend) => resend.contacts.segments.remove(payload),
43
+ errorCode: 'remove_segment_error',
44
+ successMsg: `Contact removed from segment: ${segmentId}`,
45
+ },
46
+ globalOpts,
47
+ );
48
+ });
@@ -0,0 +1,39 @@
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 { renderSegmentsTable } from '../segments/utils';
6
+ import { segmentContactIdentifier } from './utils';
7
+
8
+ export const listContactSegmentsCommand = new Command('segments')
9
+ .description('List the segments a contact belongs to')
10
+ .argument('<id>', 'Contact UUID or email address')
11
+ .addHelpText(
12
+ 'after',
13
+ buildHelpText({
14
+ context: `The <id> argument accepts either a UUID or an email address.`,
15
+ output: ` {"object":"list","data":[{"id":"<segment-uuid>","name":"Newsletter Subscribers","created_at":"..."}],"has_more":false}`,
16
+ errorCodes: ['auth_error', 'list_error'],
17
+ examples: [
18
+ 'resend contacts segments 479e3145-dd38-4932-8c0c-e58b548c9e76',
19
+ 'resend contacts segments user@example.com',
20
+ 'resend contacts segments 479e3145-dd38-4932-8c0c-e58b548c9e76 --json',
21
+ ],
22
+ }),
23
+ )
24
+ .action(async (id, _opts, cmd) => {
25
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
26
+ await runList(
27
+ {
28
+ spinner: {
29
+ loading: 'Fetching segments...',
30
+ success: 'Segments fetched',
31
+ fail: 'Failed to list segments',
32
+ },
33
+ sdkCall: (resend) =>
34
+ resend.contacts.segments.list(segmentContactIdentifier(id)),
35
+ onInteractive: (list) => console.log(renderSegmentsTable(list.data)),
36
+ },
37
+ globalOpts,
38
+ );
39
+ });
@@ -0,0 +1,45 @@
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 { contactIdentifier, renderContactTopicsTable } from './utils';
6
+
7
+ export const listContactTopicsCommand = new Command('topics')
8
+ .description("List a contact's topic subscriptions")
9
+ .argument('<id>', 'Contact UUID or email address')
10
+ .addHelpText(
11
+ 'after',
12
+ buildHelpText({
13
+ context: `The <id> argument accepts either a UUID or an email address.
14
+
15
+ Topics control which broadcast email types a contact receives.
16
+ subscription values: "opt_in" (receiving) | "opt_out" (not receiving)
17
+
18
+ Use "resend contacts update-topics <id>" to change subscription statuses.`,
19
+ output: ` {"object":"list","data":[{"id":"...","name":"Product Updates","description":"...","subscription":"opt_in"}],"has_more":false}`,
20
+ errorCodes: ['auth_error', 'list_error'],
21
+ examples: [
22
+ 'resend contacts topics 479e3145-dd38-4932-8c0c-e58b548c9e76',
23
+ 'resend contacts topics user@example.com',
24
+ 'resend contacts topics 479e3145-dd38-4932-8c0c-e58b548c9e76 --json',
25
+ ],
26
+ }),
27
+ )
28
+ .action(async (id, _opts, cmd) => {
29
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
30
+ // ListContactTopicsBaseOptions uses optional { id?, email? } (not a discriminated
31
+ // union), so contactIdentifier's result is directly assignable without a cast.
32
+ await runList(
33
+ {
34
+ spinner: {
35
+ loading: 'Fetching topic subscriptions...',
36
+ success: 'Topic subscriptions fetched',
37
+ fail: 'Failed to list topic subscriptions',
38
+ },
39
+ sdkCall: (resend) => resend.contacts.topics.list(contactIdentifier(id)),
40
+ onInteractive: (list) =>
41
+ console.log(renderContactTopicsTable(list.data)),
42
+ },
43
+ globalOpts,
44
+ );
45
+ });
@@ -0,0 +1,90 @@
1
+ import * as p from '@clack/prompts';
2
+ import { Command } from '@commander-js/extra-typings';
3
+ import type { GlobalOpts } from '../../lib/client';
4
+ import { requireClient } from '../../lib/client';
5
+ import { buildHelpText } from '../../lib/help-text';
6
+ import { outputError, outputResult } from '../../lib/output';
7
+ import { cancelAndExit } from '../../lib/prompts';
8
+ import { withSpinner } from '../../lib/spinner';
9
+ import { isInteractive } from '../../lib/tty';
10
+ import { contactIdentifier, parseTopicsJson } from './utils';
11
+
12
+ export const updateContactTopicsCommand = new Command('update-topics')
13
+ .description("Update a contact's topic subscription statuses")
14
+ .argument('<id>', 'Contact UUID or email address')
15
+ .option(
16
+ '--topics <json>',
17
+ 'JSON array of topic subscriptions (required) — e.g. \'[{"id":"topic-uuid","subscription":"opt_in"}]\'',
18
+ )
19
+ .addHelpText(
20
+ 'after',
21
+ buildHelpText({
22
+ context: `The <id> argument accepts either a UUID or an email address.
23
+
24
+ Non-interactive: --topics is required.
25
+
26
+ Topics JSON format:
27
+ '[{"id":"<topic-uuid>","subscription":"opt_in"}]'
28
+ subscription values: "opt_in" | "opt_out"
29
+
30
+ This operation replaces all topic subscriptions for the specified topics.
31
+ Topics not included in the array are left unchanged.`,
32
+ output: ` {"id":"<contact-id>"}`,
33
+ errorCodes: [
34
+ 'auth_error',
35
+ 'missing_topics',
36
+ 'invalid_topics',
37
+ 'update_topics_error',
38
+ ],
39
+ examples: [
40
+ `resend contacts update-topics 479e3145-dd38-4932-8c0c-e58b548c9e76 --topics '[{"id":"topic-uuid","subscription":"opt_in"}]'`,
41
+ `resend contacts update-topics user@example.com --topics '[{"id":"t1","subscription":"opt_out"},{"id":"t2","subscription":"opt_in"}]' --json`,
42
+ ],
43
+ }),
44
+ )
45
+ .action(async (id, opts, cmd) => {
46
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
47
+ const resend = requireClient(globalOpts);
48
+
49
+ let topicsJson = opts.topics;
50
+
51
+ if (!topicsJson) {
52
+ if (!isInteractive()) {
53
+ outputError(
54
+ { message: 'Missing --topics flag.', code: 'missing_topics' },
55
+ { json: globalOpts.json },
56
+ );
57
+ }
58
+ const result = await p.text({
59
+ message:
60
+ 'Topics JSON (e.g. \'[{"id":"topic-uuid","subscription":"opt_in"}]\')',
61
+ placeholder: '[{"id":"topic-uuid","subscription":"opt_in"}]',
62
+ validate: (v) => (!v ? 'Required' : undefined),
63
+ });
64
+ if (p.isCancel(result)) {
65
+ cancelAndExit('Cancelled.');
66
+ }
67
+ topicsJson = result;
68
+ }
69
+
70
+ const topics = parseTopicsJson(topicsJson, globalOpts);
71
+
72
+ // contactIdentifier's result is directly assignable: UpdateContactTopicsBaseOptions
73
+ // uses optional { id?, email? } (not a discriminated union).
74
+ const data = await withSpinner(
75
+ {
76
+ loading: 'Updating topic subscriptions...',
77
+ success: 'Topic subscriptions updated',
78
+ fail: 'Failed to update topic subscriptions',
79
+ },
80
+ () => resend.contacts.topics.update({ ...contactIdentifier(id), topics }),
81
+ 'update_topics_error',
82
+ globalOpts,
83
+ );
84
+
85
+ if (!globalOpts.json && isInteractive()) {
86
+ console.log(`Topic subscriptions updated for contact: ${id}`);
87
+ } else {
88
+ outputResult(data, { json: globalOpts.json });
89
+ }
90
+ });
@@ -0,0 +1,77 @@
1
+ import { Command } from '@commander-js/extra-typings';
2
+ import type { UpdateContactOptions } from 'resend';
3
+ import { runWrite } from '../../lib/actions';
4
+ import type { GlobalOpts } from '../../lib/client';
5
+ import { buildHelpText } from '../../lib/help-text';
6
+ import { contactIdentifier, parsePropertiesJson } from './utils';
7
+
8
+ export const updateContactCommand = new Command('update')
9
+ .description("Update a contact's subscription status or custom properties")
10
+ .argument(
11
+ '<id>',
12
+ 'Contact UUID or email address — both are accepted by the API',
13
+ )
14
+ .option(
15
+ '--unsubscribed',
16
+ 'Globally unsubscribe the contact from all broadcasts',
17
+ )
18
+ .option(
19
+ '--no-unsubscribed',
20
+ 'Re-subscribe the contact (clears the global unsubscribe flag)',
21
+ )
22
+ .option(
23
+ '--properties <json>',
24
+ 'JSON object of properties to merge (e.g. \'{"company":"Acme"}\'); set a key to null to clear it',
25
+ )
26
+ .addHelpText(
27
+ 'after',
28
+ buildHelpText({
29
+ context: `The <id> argument accepts either a UUID or an email address.
30
+
31
+ Subscription toggle:
32
+ --unsubscribed Sets unsubscribed: true — contact will not receive any broadcasts.
33
+ --no-unsubscribed Sets unsubscribed: false — re-enables broadcast delivery.
34
+ Omitting both flags leaves the subscription status unchanged.
35
+
36
+ Properties: --properties merges the given JSON object with existing properties.
37
+ Set a key to null to clear it: '{"company":null}'.`,
38
+ output: ` {"object":"contact","id":"<id>"}`,
39
+ errorCodes: ['auth_error', 'invalid_properties', 'update_error'],
40
+ examples: [
41
+ 'resend contacts update 479e3145-dd38-4932-8c0c-e58b548c9e76 --unsubscribed',
42
+ 'resend contacts update user@example.com --no-unsubscribed',
43
+ `resend contacts update 479e3145-dd38-4932-8c0c-e58b548c9e76 --properties '{"plan":"pro"}'`,
44
+ 'resend contacts update user@example.com --unsubscribed --json',
45
+ ],
46
+ }),
47
+ )
48
+ .action(async (id, opts, cmd) => {
49
+ const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
50
+
51
+ const properties = parsePropertiesJson(opts.properties, globalOpts);
52
+
53
+ // contactIdentifier resolves UUID vs email. The spread of a discriminated
54
+ // union requires an explicit cast because TypeScript cannot narrow it
55
+ // through a spread at the call site.
56
+ const payload = {
57
+ ...contactIdentifier(id),
58
+ ...(opts.unsubscribed !== undefined && {
59
+ unsubscribed: opts.unsubscribed,
60
+ }),
61
+ ...(properties && { properties }),
62
+ } as UpdateContactOptions;
63
+
64
+ await runWrite(
65
+ {
66
+ spinner: {
67
+ loading: 'Updating contact...',
68
+ success: 'Contact updated',
69
+ fail: 'Failed to update contact',
70
+ },
71
+ sdkCall: (resend) => resend.contacts.update(payload),
72
+ errorCode: 'update_error',
73
+ successMsg: `Contact updated: ${id}`,
74
+ },
75
+ globalOpts,
76
+ );
77
+ });
@@ -0,0 +1,119 @@
1
+ import type { ContactSegmentsBaseOptions, ContactTopic } from 'resend';
2
+ import type { GlobalOpts } from '../../lib/client';
3
+ import { outputError } from '../../lib/output';
4
+ import { renderTable } from '../../lib/table';
5
+
6
+ // ─── Table renderers ─────────────────────────────────────────────────────────
7
+
8
+ export function renderContactsTable(
9
+ contacts: Array<{
10
+ id: string;
11
+ email: string;
12
+ first_name: string | null;
13
+ last_name: string | null;
14
+ unsubscribed: boolean;
15
+ }>,
16
+ ): string {
17
+ const rows = contacts.map((c) => [
18
+ c.email,
19
+ c.first_name ?? '',
20
+ c.last_name ?? '',
21
+ c.unsubscribed ? 'yes' : 'no',
22
+ c.id,
23
+ ]);
24
+ return renderTable(
25
+ ['Email', 'First Name', 'Last Name', 'Unsubscribed', 'ID'],
26
+ rows,
27
+ '(no contacts)',
28
+ );
29
+ }
30
+
31
+ export function renderContactTopicsTable(topics: ContactTopic[]): string {
32
+ const rows = topics.map((t) => [
33
+ t.name,
34
+ t.subscription,
35
+ t.id,
36
+ t.description ?? '',
37
+ ]);
38
+ return renderTable(
39
+ ['Name', 'Subscription', 'ID', 'Description'],
40
+ rows,
41
+ '(no topic subscriptions)',
42
+ );
43
+ }
44
+
45
+ // ─── Contact identifier helpers ───────────────────────────────────────────────
46
+ //
47
+ // The Resend SDK uses two different discriminated-union shapes depending on
48
+ // the API surface:
49
+ //
50
+ // • contactIdentifier — produces { id } | { email } for endpoints that
51
+ // accept SelectingField (update, get, remove) or { id?, email? }
52
+ // (topics list/update).
53
+ //
54
+ // • segmentContactIdentifier — produces { contactId } | { email } for the
55
+ // contacts.segments.* endpoints, which use ContactSegmentsBaseOptions.
56
+ //
57
+ // Centralising the `str.includes('@')` check here prevents it from drifting
58
+ // across six separate command files.
59
+
60
+ export function contactIdentifier(
61
+ id: string,
62
+ ): { id: string } | { email: string } {
63
+ return id.includes('@') ? { email: id } : { id };
64
+ }
65
+
66
+ export function segmentContactIdentifier(
67
+ id: string,
68
+ ): ContactSegmentsBaseOptions {
69
+ return id.includes('@') ? { email: id } : { contactId: id };
70
+ }
71
+
72
+ // ─── JSON flag helpers ────────────────────────────────────────────────────────
73
+
74
+ export function parseTopicsJson(
75
+ raw: string,
76
+ globalOpts: GlobalOpts,
77
+ ): Array<{ id: string; subscription: 'opt_in' | 'opt_out' }> {
78
+ let parsed: unknown;
79
+ try {
80
+ parsed = JSON.parse(raw);
81
+ } catch {
82
+ outputError(
83
+ {
84
+ message:
85
+ 'Invalid --topics JSON. Expected an array of {id, subscription} objects.',
86
+ code: 'invalid_topics',
87
+ },
88
+ { json: globalOpts.json },
89
+ );
90
+ }
91
+ if (!Array.isArray(parsed)) {
92
+ outputError(
93
+ {
94
+ message:
95
+ 'Invalid --topics JSON. Expected an array of {id, subscription} objects.',
96
+ code: 'invalid_topics',
97
+ },
98
+ { json: globalOpts.json },
99
+ );
100
+ }
101
+ return parsed as Array<{ id: string; subscription: 'opt_in' | 'opt_out' }>;
102
+ }
103
+
104
+ export function parsePropertiesJson(
105
+ raw: string | undefined,
106
+ globalOpts: GlobalOpts,
107
+ ): Record<string, string | number | null> | undefined {
108
+ if (!raw) {
109
+ return undefined;
110
+ }
111
+ try {
112
+ return JSON.parse(raw) as Record<string, string | number | null>;
113
+ } catch {
114
+ outputError(
115
+ { message: 'Invalid --properties JSON.', code: 'invalid_properties' },
116
+ { json: globalOpts.json },
117
+ );
118
+ }
119
+ }