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,17 +0,0 @@
1
- import type { ContactProperty } from 'resend';
2
- import { renderTable } from '../../lib/table';
3
-
4
- export function renderContactPropertiesTable(props: ContactProperty[]): string {
5
- const rows = props.map((prop) => [
6
- prop.key,
7
- prop.type,
8
- prop.fallbackValue != null ? String(prop.fallbackValue) : '',
9
- prop.id,
10
- prop.createdAt,
11
- ]);
12
- return renderTable(
13
- ['Key', 'Type', 'Fallback Value', 'ID', 'Created'],
14
- rows,
15
- '(no contact properties)',
16
- );
17
- }
@@ -1,78 +0,0 @@
1
- import * as p from '@clack/prompts';
2
- import { Command } from '@commander-js/extra-typings';
3
- import type { AddContactSegmentOptions } from 'resend';
4
- import type { GlobalOpts } from '../../lib/client';
5
- import { requireClient } from '../../lib/client';
6
- import { buildHelpText } from '../../lib/help-text';
7
- import { outputError, outputResult } from '../../lib/output';
8
- import { cancelAndExit } from '../../lib/prompts';
9
- import { withSpinner } from '../../lib/spinner';
10
- import { isInteractive } from '../../lib/tty';
11
- import { segmentContactIdentifier } from './utils';
12
-
13
- export const addContactSegmentCommand = new Command('add-segment')
14
- .description('Add a contact to a segment')
15
- .argument('<contactId>', 'Contact UUID or email address')
16
- .option('--segment-id <id>', 'Segment ID to add the contact to (required)')
17
- .addHelpText(
18
- 'after',
19
- buildHelpText({
20
- context: `The <contactId> argument accepts either a UUID or an email address.
21
-
22
- Non-interactive: --segment-id is required.`,
23
- output: ` {"id":"<segment-membership-id>"}`,
24
- errorCodes: ['auth_error', 'missing_segment_id', 'add_segment_error'],
25
- examples: [
26
- 'resend contacts add-segment 479e3145-dd38-4932-8c0c-e58b548c9e76 --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
27
- 'resend contacts add-segment user@example.com --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --json',
28
- ],
29
- }),
30
- )
31
- .action(async (contactId, opts, cmd) => {
32
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
33
- const resend = requireClient(globalOpts);
34
-
35
- let segmentId = opts.segmentId;
36
-
37
- if (!segmentId) {
38
- if (!isInteractive()) {
39
- outputError(
40
- { message: 'Missing --segment-id flag.', code: 'missing_segment_id' },
41
- { json: globalOpts.json },
42
- );
43
- }
44
- const result = await p.text({
45
- message: 'Segment ID',
46
- placeholder: '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
47
- validate: (v) => (!v ? 'Required' : undefined),
48
- });
49
- if (p.isCancel(result)) {
50
- cancelAndExit('Cancelled.');
51
- }
52
- segmentId = result;
53
- }
54
-
55
- // segmentContactIdentifier resolves UUID vs email for the ContactSegmentsBaseOptions
56
- // discriminated union. The spread of that union requires an explicit cast.
57
- const payload = {
58
- ...segmentContactIdentifier(contactId),
59
- segmentId,
60
- } as AddContactSegmentOptions;
61
-
62
- const data = await withSpinner(
63
- {
64
- loading: 'Adding contact to segment...',
65
- success: 'Contact added to segment',
66
- fail: 'Failed to add contact to segment',
67
- },
68
- () => resend.contacts.segments.add(payload),
69
- 'add_segment_error',
70
- globalOpts,
71
- );
72
-
73
- if (!globalOpts.json && isInteractive()) {
74
- console.log(`Contact added to segment: ${segmentId}`);
75
- } else {
76
- outputResult(data, { json: globalOpts.json });
77
- }
78
- });
@@ -1,122 +0,0 @@
1
- import * as p from '@clack/prompts';
2
- import { Command } 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 { cancelAndExit, requireText } from '../../lib/prompts';
7
- import { isInteractive } from '../../lib/tty';
8
- import { parsePropertiesJson } from './utils';
9
-
10
- export const createContactCommand = new Command('create')
11
- .description('Create a new contact')
12
- .option('--email <email>', 'Contact email address (required)')
13
- .option('--first-name <name>', 'First name')
14
- .option('--last-name <name>', 'Last name')
15
- .option(
16
- '--unsubscribed',
17
- 'Globally unsubscribe the contact from all broadcasts',
18
- )
19
- .option(
20
- '--properties <json>',
21
- 'Custom properties as a JSON string (e.g. \'{"company":"Acme"}\')',
22
- )
23
- .option(
24
- '--segment-id <id...>',
25
- 'Segment ID to add the contact to on creation (repeatable: --segment-id abc --segment-id def)',
26
- )
27
- .addHelpText(
28
- 'after',
29
- buildHelpText({
30
- context: `Non-interactive: --email is required. All other flags are optional.
31
-
32
- Properties: pass a JSON object string to --properties (e.g. '{"plan":"pro","company":"Acme"}').
33
- Properties are stored as custom contact attributes. To clear a property, set it to null.
34
- firstName and lastName are convenience aliases — they map to FIRST_NAME/LAST_NAME properties internally.
35
-
36
- Segments: use --segment-id once per segment to add the contact to one or more segments on creation.
37
-
38
- Unsubscribed: setting --unsubscribed is a team-wide opt-out from all broadcasts, regardless of segments/topics.`,
39
- output: ` {"object":"contact","id":"<id>"}`,
40
- errorCodes: [
41
- 'auth_error',
42
- 'missing_email',
43
- 'invalid_properties',
44
- 'create_error',
45
- ],
46
- examples: [
47
- 'resend contacts create --email jane@example.com',
48
- 'resend contacts create --email jane@example.com --first-name Jane --last-name Smith',
49
- 'resend contacts create --email jane@example.com --unsubscribed',
50
- `resend contacts create --email jane@example.com --properties '{"company":"Acme","plan":"pro"}'`,
51
- 'resend contacts create --email jane@example.com --segment-id 7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d --segment-id a2f4c6e8-1b3d-5f7a-9c2e-4d6f8a1b3c5e',
52
- 'resend contacts create --email jane@example.com --first-name Jane --json',
53
- ],
54
- }),
55
- )
56
- .action(async (opts, cmd) => {
57
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
58
-
59
- const email = await requireText(
60
- opts.email,
61
- { message: 'Email address', placeholder: 'user@example.com' },
62
- { message: 'Missing --email flag.', code: 'missing_email' },
63
- globalOpts,
64
- );
65
-
66
- let firstName = opts.firstName;
67
- let lastName = opts.lastName;
68
-
69
- if (isInteractive() && !opts.firstName) {
70
- const result = await p.text({
71
- message: 'First name (optional)',
72
- placeholder: 'Jane',
73
- });
74
- if (p.isCancel(result)) {
75
- cancelAndExit('Cancelled.');
76
- }
77
- if (result) {
78
- firstName = result;
79
- }
80
- }
81
-
82
- if (isInteractive() && !opts.lastName) {
83
- const result = await p.text({
84
- message: 'Last name (optional)',
85
- placeholder: 'Smith',
86
- });
87
- if (p.isCancel(result)) {
88
- cancelAndExit('Cancelled.');
89
- }
90
- if (result) {
91
- lastName = result;
92
- }
93
- }
94
-
95
- const properties = parsePropertiesJson(opts.properties, globalOpts);
96
- const segments = opts.segmentId ?? [];
97
-
98
- await runCreate(
99
- {
100
- spinner: {
101
- loading: 'Creating contact...',
102
- success: 'Contact created',
103
- fail: 'Failed to create contact',
104
- },
105
- sdkCall: (resend) =>
106
- resend.contacts.create({
107
- email,
108
- ...(firstName && { firstName }),
109
- ...(lastName && { lastName }),
110
- ...(opts.unsubscribed && { unsubscribed: true }),
111
- ...(properties && { properties }),
112
- ...(segments.length > 0 && {
113
- segments: segments.map((id) => ({ id })),
114
- }),
115
- }),
116
- onInteractive: (data) => {
117
- console.log(`\nContact created: ${data.id}`);
118
- },
119
- },
120
- globalOpts,
121
- );
122
- });
@@ -1,49 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { runDelete } from '../../lib/actions';
3
- import type { GlobalOpts } from '../../lib/client';
4
- import { buildHelpText } from '../../lib/help-text';
5
-
6
- export const 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
- });
@@ -1,53 +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 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
- });
@@ -1,58 +0,0 @@
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);
@@ -1,57 +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 { 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
- });
@@ -1,48 +0,0 @@
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
- });
@@ -1,39 +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 { 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
- });
@@ -1,45 +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 { 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
- });
@@ -1,90 +0,0 @@
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
- });