resend-cli 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +25 -10
  2. package/dist/cli.cjs +539 -0
  3. package/package.json +31 -12
  4. package/.claude/settings.local.json +0 -5
  5. package/.github/scripts/pr-title-check.js +0 -34
  6. package/.github/workflows/ci.yml +0 -32
  7. package/.github/workflows/pr-title-check.yml +0 -13
  8. package/.github/workflows/release.yml +0 -120
  9. package/.github/workflows/test-install-windows.yml +0 -48
  10. package/CHANGELOG.md +0 -31
  11. package/biome.json +0 -36
  12. package/bun.lock +0 -73
  13. package/bunfig.toml +0 -2
  14. package/docs/agent-dx-gaps.md +0 -167
  15. package/docs/missing-commands.md +0 -58
  16. package/docs/production-readiness.md +0 -99
  17. package/docs/secure-key-storage.md +0 -174
  18. package/install.ps1 +0 -141
  19. package/install.sh +0 -301
  20. package/renovate.json +0 -4
  21. package/src/cli.ts +0 -92
  22. package/src/commands/api-keys/create.ts +0 -114
  23. package/src/commands/api-keys/delete.ts +0 -47
  24. package/src/commands/api-keys/index.ts +0 -26
  25. package/src/commands/api-keys/list.ts +0 -35
  26. package/src/commands/api-keys/utils.ts +0 -8
  27. package/src/commands/auth/index.ts +0 -20
  28. package/src/commands/auth/login.ts +0 -234
  29. package/src/commands/auth/logout.ts +0 -105
  30. package/src/commands/broadcasts/create.ts +0 -196
  31. package/src/commands/broadcasts/delete.ts +0 -46
  32. package/src/commands/broadcasts/get.ts +0 -59
  33. package/src/commands/broadcasts/index.ts +0 -43
  34. package/src/commands/broadcasts/list.ts +0 -60
  35. package/src/commands/broadcasts/send.ts +0 -56
  36. package/src/commands/broadcasts/update.ts +0 -95
  37. package/src/commands/broadcasts/utils.ts +0 -35
  38. package/src/commands/contact-properties/create.ts +0 -118
  39. package/src/commands/contact-properties/delete.ts +0 -48
  40. package/src/commands/contact-properties/get.ts +0 -46
  41. package/src/commands/contact-properties/index.ts +0 -48
  42. package/src/commands/contact-properties/list.ts +0 -68
  43. package/src/commands/contact-properties/update.ts +0 -88
  44. package/src/commands/contact-properties/utils.ts +0 -17
  45. package/src/commands/contacts/add-segment.ts +0 -78
  46. package/src/commands/contacts/create.ts +0 -122
  47. package/src/commands/contacts/delete.ts +0 -49
  48. package/src/commands/contacts/get.ts +0 -53
  49. package/src/commands/contacts/index.ts +0 -58
  50. package/src/commands/contacts/list.ts +0 -57
  51. package/src/commands/contacts/remove-segment.ts +0 -48
  52. package/src/commands/contacts/segments.ts +0 -39
  53. package/src/commands/contacts/topics.ts +0 -45
  54. package/src/commands/contacts/update-topics.ts +0 -90
  55. package/src/commands/contacts/update.ts +0 -77
  56. package/src/commands/contacts/utils.ts +0 -119
  57. package/src/commands/doctor.ts +0 -216
  58. package/src/commands/domains/create.ts +0 -83
  59. package/src/commands/domains/delete.ts +0 -42
  60. package/src/commands/domains/get.ts +0 -47
  61. package/src/commands/domains/index.ts +0 -35
  62. package/src/commands/domains/list.ts +0 -53
  63. package/src/commands/domains/update.ts +0 -75
  64. package/src/commands/domains/utils.ts +0 -44
  65. package/src/commands/domains/verify.ts +0 -38
  66. package/src/commands/emails/batch.ts +0 -140
  67. package/src/commands/emails/index.ts +0 -24
  68. package/src/commands/emails/receiving/attachment.ts +0 -55
  69. package/src/commands/emails/receiving/attachments.ts +0 -68
  70. package/src/commands/emails/receiving/get.ts +0 -58
  71. package/src/commands/emails/receiving/index.ts +0 -28
  72. package/src/commands/emails/receiving/list.ts +0 -59
  73. package/src/commands/emails/receiving/utils.ts +0 -38
  74. package/src/commands/emails/send.ts +0 -189
  75. package/src/commands/open.ts +0 -24
  76. package/src/commands/segments/create.ts +0 -50
  77. package/src/commands/segments/delete.ts +0 -47
  78. package/src/commands/segments/get.ts +0 -38
  79. package/src/commands/segments/index.ts +0 -36
  80. package/src/commands/segments/list.ts +0 -58
  81. package/src/commands/segments/utils.ts +0 -7
  82. package/src/commands/teams/index.ts +0 -10
  83. package/src/commands/teams/list.ts +0 -35
  84. package/src/commands/teams/remove.ts +0 -86
  85. package/src/commands/teams/switch.ts +0 -76
  86. package/src/commands/topics/create.ts +0 -73
  87. package/src/commands/topics/delete.ts +0 -47
  88. package/src/commands/topics/get.ts +0 -42
  89. package/src/commands/topics/index.ts +0 -42
  90. package/src/commands/topics/list.ts +0 -34
  91. package/src/commands/topics/update.ts +0 -59
  92. package/src/commands/topics/utils.ts +0 -16
  93. package/src/commands/webhooks/create.ts +0 -128
  94. package/src/commands/webhooks/delete.ts +0 -49
  95. package/src/commands/webhooks/get.ts +0 -42
  96. package/src/commands/webhooks/index.ts +0 -44
  97. package/src/commands/webhooks/list.ts +0 -55
  98. package/src/commands/webhooks/update.ts +0 -83
  99. package/src/commands/webhooks/utils.ts +0 -36
  100. package/src/commands/whoami.ts +0 -71
  101. package/src/lib/actions.ts +0 -157
  102. package/src/lib/client.ts +0 -37
  103. package/src/lib/config.ts +0 -217
  104. package/src/lib/files.ts +0 -15
  105. package/src/lib/help-text.ts +0 -38
  106. package/src/lib/output.ts +0 -54
  107. package/src/lib/pagination.ts +0 -36
  108. package/src/lib/prompts.ts +0 -149
  109. package/src/lib/spinner.ts +0 -100
  110. package/src/lib/table.ts +0 -57
  111. package/src/lib/tty.ts +0 -28
  112. package/src/lib/update-check.ts +0 -172
  113. package/src/lib/version.ts +0 -4
  114. package/tests/commands/api-keys/create.test.ts +0 -195
  115. package/tests/commands/api-keys/delete.test.ts +0 -156
  116. package/tests/commands/api-keys/list.test.ts +0 -133
  117. package/tests/commands/auth/login.test.ts +0 -156
  118. package/tests/commands/auth/logout.test.ts +0 -146
  119. package/tests/commands/broadcasts/create.test.ts +0 -447
  120. package/tests/commands/broadcasts/delete.test.ts +0 -182
  121. package/tests/commands/broadcasts/get.test.ts +0 -146
  122. package/tests/commands/broadcasts/list.test.ts +0 -196
  123. package/tests/commands/broadcasts/send.test.ts +0 -161
  124. package/tests/commands/broadcasts/update.test.ts +0 -283
  125. package/tests/commands/contact-properties/create.test.ts +0 -250
  126. package/tests/commands/contact-properties/delete.test.ts +0 -183
  127. package/tests/commands/contact-properties/get.test.ts +0 -144
  128. package/tests/commands/contact-properties/list.test.ts +0 -180
  129. package/tests/commands/contact-properties/update.test.ts +0 -216
  130. package/tests/commands/contacts/add-segment.test.ts +0 -188
  131. package/tests/commands/contacts/create.test.ts +0 -270
  132. package/tests/commands/contacts/delete.test.ts +0 -192
  133. package/tests/commands/contacts/get.test.ts +0 -148
  134. package/tests/commands/contacts/list.test.ts +0 -175
  135. package/tests/commands/contacts/remove-segment.test.ts +0 -166
  136. package/tests/commands/contacts/segments.test.ts +0 -167
  137. package/tests/commands/contacts/topics.test.ts +0 -163
  138. package/tests/commands/contacts/update-topics.test.ts +0 -247
  139. package/tests/commands/contacts/update.test.ts +0 -205
  140. package/tests/commands/doctor.test.ts +0 -165
  141. package/tests/commands/domains/create.test.ts +0 -192
  142. package/tests/commands/domains/delete.test.ts +0 -156
  143. package/tests/commands/domains/get.test.ts +0 -137
  144. package/tests/commands/domains/list.test.ts +0 -164
  145. package/tests/commands/domains/update.test.ts +0 -223
  146. package/tests/commands/domains/verify.test.ts +0 -117
  147. package/tests/commands/emails/batch.test.ts +0 -313
  148. package/tests/commands/emails/receiving/attachment.test.ts +0 -140
  149. package/tests/commands/emails/receiving/attachments.test.ts +0 -168
  150. package/tests/commands/emails/receiving/get.test.ts +0 -140
  151. package/tests/commands/emails/receiving/list.test.ts +0 -181
  152. package/tests/commands/emails/send.test.ts +0 -309
  153. package/tests/commands/segments/create.test.ts +0 -163
  154. package/tests/commands/segments/delete.test.ts +0 -182
  155. package/tests/commands/segments/get.test.ts +0 -137
  156. package/tests/commands/segments/list.test.ts +0 -173
  157. package/tests/commands/teams/list.test.ts +0 -63
  158. package/tests/commands/teams/remove.test.ts +0 -103
  159. package/tests/commands/teams/switch.test.ts +0 -96
  160. package/tests/commands/topics/create.test.ts +0 -191
  161. package/tests/commands/topics/delete.test.ts +0 -156
  162. package/tests/commands/topics/get.test.ts +0 -125
  163. package/tests/commands/topics/list.test.ts +0 -124
  164. package/tests/commands/topics/update.test.ts +0 -177
  165. package/tests/commands/webhooks/create.test.ts +0 -224
  166. package/tests/commands/webhooks/delete.test.ts +0 -156
  167. package/tests/commands/webhooks/get.test.ts +0 -125
  168. package/tests/commands/webhooks/list.test.ts +0 -177
  169. package/tests/commands/webhooks/update.test.ts +0 -206
  170. package/tests/commands/whoami.test.ts +0 -99
  171. package/tests/helpers.ts +0 -93
  172. package/tests/lib/client.test.ts +0 -71
  173. package/tests/lib/config.test.ts +0 -445
  174. package/tests/lib/files.test.ts +0 -65
  175. package/tests/lib/help-text.test.ts +0 -97
  176. package/tests/lib/output.test.ts +0 -127
  177. package/tests/lib/prompts.test.ts +0 -178
  178. package/tests/lib/spinner.test.ts +0 -146
  179. package/tests/lib/table.test.ts +0 -63
  180. package/tests/lib/tty.test.ts +0 -85
  181. package/tests/lib/update-check.test.ts +0 -169
  182. package/tsconfig.json +0 -14
@@ -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
- });