resend-cli 1.2.1 → 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 (191) hide show
  1. package/biome.json +1 -1
  2. package/bun.lock +0 -3
  3. package/package.json +2 -3
  4. package/src/cli.ts +11 -1
  5. package/src/commands/auth/login.ts +35 -8
  6. package/src/commands/doctor.ts +33 -115
  7. package/src/commands/teams/remove.ts +5 -2
  8. package/src/commands/teams/switch.ts +3 -0
  9. package/src/lib/config.ts +37 -31
  10. package/src/lib/spinner.ts +17 -10
  11. package/src/lib/update-check.ts +172 -0
  12. package/tests/commands/auth/login.test.ts +37 -0
  13. package/tests/lib/config.test.ts +38 -7
  14. package/tests/lib/update-check.test.ts +169 -0
  15. package/.claude/worktrees/emails-list/.claude/settings.local.json +0 -5
  16. package/.claude/worktrees/emails-list/.github/scripts/pr-title-check.js +0 -34
  17. package/.claude/worktrees/emails-list/.github/workflows/ci.yml +0 -32
  18. package/.claude/worktrees/emails-list/.github/workflows/pr-title-check.yml +0 -13
  19. package/.claude/worktrees/emails-list/.github/workflows/release.yml +0 -93
  20. package/.claude/worktrees/emails-list/CHANGELOG.md +0 -31
  21. package/.claude/worktrees/emails-list/LICENSE +0 -21
  22. package/.claude/worktrees/emails-list/README.md +0 -424
  23. package/.claude/worktrees/emails-list/biome.json +0 -36
  24. package/.claude/worktrees/emails-list/bun.lock +0 -76
  25. package/.claude/worktrees/emails-list/bunfig.toml +0 -2
  26. package/.claude/worktrees/emails-list/install.ps1 +0 -140
  27. package/.claude/worktrees/emails-list/install.sh +0 -301
  28. package/.claude/worktrees/emails-list/package.json +0 -43
  29. package/.claude/worktrees/emails-list/renovate.json +0 -6
  30. package/.claude/worktrees/emails-list/src/cli.ts +0 -74
  31. package/.claude/worktrees/emails-list/src/commands/api-keys/create.ts +0 -114
  32. package/.claude/worktrees/emails-list/src/commands/api-keys/delete.ts +0 -47
  33. package/.claude/worktrees/emails-list/src/commands/api-keys/index.ts +0 -26
  34. package/.claude/worktrees/emails-list/src/commands/api-keys/list.ts +0 -35
  35. package/.claude/worktrees/emails-list/src/commands/api-keys/utils.ts +0 -8
  36. package/.claude/worktrees/emails-list/src/commands/auth/index.ts +0 -20
  37. package/.claude/worktrees/emails-list/src/commands/auth/login.ts +0 -207
  38. package/.claude/worktrees/emails-list/src/commands/auth/logout.ts +0 -105
  39. package/.claude/worktrees/emails-list/src/commands/broadcasts/create.ts +0 -196
  40. package/.claude/worktrees/emails-list/src/commands/broadcasts/delete.ts +0 -46
  41. package/.claude/worktrees/emails-list/src/commands/broadcasts/get.ts +0 -59
  42. package/.claude/worktrees/emails-list/src/commands/broadcasts/index.ts +0 -43
  43. package/.claude/worktrees/emails-list/src/commands/broadcasts/list.ts +0 -60
  44. package/.claude/worktrees/emails-list/src/commands/broadcasts/send.ts +0 -56
  45. package/.claude/worktrees/emails-list/src/commands/broadcasts/update.ts +0 -95
  46. package/.claude/worktrees/emails-list/src/commands/broadcasts/utils.ts +0 -35
  47. package/.claude/worktrees/emails-list/src/commands/contact-properties/create.ts +0 -118
  48. package/.claude/worktrees/emails-list/src/commands/contact-properties/delete.ts +0 -48
  49. package/.claude/worktrees/emails-list/src/commands/contact-properties/get.ts +0 -46
  50. package/.claude/worktrees/emails-list/src/commands/contact-properties/index.ts +0 -48
  51. package/.claude/worktrees/emails-list/src/commands/contact-properties/list.ts +0 -68
  52. package/.claude/worktrees/emails-list/src/commands/contact-properties/update.ts +0 -88
  53. package/.claude/worktrees/emails-list/src/commands/contact-properties/utils.ts +0 -17
  54. package/.claude/worktrees/emails-list/src/commands/contacts/add-segment.ts +0 -78
  55. package/.claude/worktrees/emails-list/src/commands/contacts/create.ts +0 -122
  56. package/.claude/worktrees/emails-list/src/commands/contacts/delete.ts +0 -49
  57. package/.claude/worktrees/emails-list/src/commands/contacts/get.ts +0 -53
  58. package/.claude/worktrees/emails-list/src/commands/contacts/index.ts +0 -58
  59. package/.claude/worktrees/emails-list/src/commands/contacts/list.ts +0 -57
  60. package/.claude/worktrees/emails-list/src/commands/contacts/remove-segment.ts +0 -48
  61. package/.claude/worktrees/emails-list/src/commands/contacts/segments.ts +0 -39
  62. package/.claude/worktrees/emails-list/src/commands/contacts/topics.ts +0 -45
  63. package/.claude/worktrees/emails-list/src/commands/contacts/update-topics.ts +0 -90
  64. package/.claude/worktrees/emails-list/src/commands/contacts/update.ts +0 -77
  65. package/.claude/worktrees/emails-list/src/commands/contacts/utils.ts +0 -119
  66. package/.claude/worktrees/emails-list/src/commands/doctor.ts +0 -298
  67. package/.claude/worktrees/emails-list/src/commands/domains/create.ts +0 -83
  68. package/.claude/worktrees/emails-list/src/commands/domains/delete.ts +0 -42
  69. package/.claude/worktrees/emails-list/src/commands/domains/get.ts +0 -47
  70. package/.claude/worktrees/emails-list/src/commands/domains/index.ts +0 -35
  71. package/.claude/worktrees/emails-list/src/commands/domains/list.ts +0 -53
  72. package/.claude/worktrees/emails-list/src/commands/domains/update.ts +0 -75
  73. package/.claude/worktrees/emails-list/src/commands/domains/utils.ts +0 -44
  74. package/.claude/worktrees/emails-list/src/commands/domains/verify.ts +0 -38
  75. package/.claude/worktrees/emails-list/src/commands/emails/batch.ts +0 -140
  76. package/.claude/worktrees/emails-list/src/commands/emails/index.ts +0 -28
  77. package/.claude/worktrees/emails-list/src/commands/emails/list.ts +0 -73
  78. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachment.ts +0 -55
  79. package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachments.ts +0 -68
  80. package/.claude/worktrees/emails-list/src/commands/emails/receiving/get.ts +0 -58
  81. package/.claude/worktrees/emails-list/src/commands/emails/receiving/index.ts +0 -28
  82. package/.claude/worktrees/emails-list/src/commands/emails/receiving/list.ts +0 -59
  83. package/.claude/worktrees/emails-list/src/commands/emails/receiving/utils.ts +0 -38
  84. package/.claude/worktrees/emails-list/src/commands/emails/send.ts +0 -189
  85. package/.claude/worktrees/emails-list/src/commands/open.ts +0 -24
  86. package/.claude/worktrees/emails-list/src/commands/segments/create.ts +0 -50
  87. package/.claude/worktrees/emails-list/src/commands/segments/delete.ts +0 -47
  88. package/.claude/worktrees/emails-list/src/commands/segments/get.ts +0 -38
  89. package/.claude/worktrees/emails-list/src/commands/segments/index.ts +0 -36
  90. package/.claude/worktrees/emails-list/src/commands/segments/list.ts +0 -58
  91. package/.claude/worktrees/emails-list/src/commands/segments/utils.ts +0 -7
  92. package/.claude/worktrees/emails-list/src/commands/teams/index.ts +0 -10
  93. package/.claude/worktrees/emails-list/src/commands/teams/list.ts +0 -35
  94. package/.claude/worktrees/emails-list/src/commands/teams/remove.ts +0 -83
  95. package/.claude/worktrees/emails-list/src/commands/teams/switch.ts +0 -73
  96. package/.claude/worktrees/emails-list/src/commands/topics/create.ts +0 -73
  97. package/.claude/worktrees/emails-list/src/commands/topics/delete.ts +0 -47
  98. package/.claude/worktrees/emails-list/src/commands/topics/get.ts +0 -42
  99. package/.claude/worktrees/emails-list/src/commands/topics/index.ts +0 -42
  100. package/.claude/worktrees/emails-list/src/commands/topics/list.ts +0 -34
  101. package/.claude/worktrees/emails-list/src/commands/topics/update.ts +0 -59
  102. package/.claude/worktrees/emails-list/src/commands/topics/utils.ts +0 -16
  103. package/.claude/worktrees/emails-list/src/commands/webhooks/create.ts +0 -128
  104. package/.claude/worktrees/emails-list/src/commands/webhooks/delete.ts +0 -49
  105. package/.claude/worktrees/emails-list/src/commands/webhooks/get.ts +0 -42
  106. package/.claude/worktrees/emails-list/src/commands/webhooks/index.ts +0 -44
  107. package/.claude/worktrees/emails-list/src/commands/webhooks/list.ts +0 -55
  108. package/.claude/worktrees/emails-list/src/commands/webhooks/update.ts +0 -83
  109. package/.claude/worktrees/emails-list/src/commands/webhooks/utils.ts +0 -36
  110. package/.claude/worktrees/emails-list/src/commands/whoami.ts +0 -71
  111. package/.claude/worktrees/emails-list/src/lib/actions.ts +0 -157
  112. package/.claude/worktrees/emails-list/src/lib/client.ts +0 -34
  113. package/.claude/worktrees/emails-list/src/lib/config.ts +0 -211
  114. package/.claude/worktrees/emails-list/src/lib/files.ts +0 -15
  115. package/.claude/worktrees/emails-list/src/lib/help-text.ts +0 -38
  116. package/.claude/worktrees/emails-list/src/lib/output.ts +0 -54
  117. package/.claude/worktrees/emails-list/src/lib/pagination.ts +0 -36
  118. package/.claude/worktrees/emails-list/src/lib/prompts.ts +0 -149
  119. package/.claude/worktrees/emails-list/src/lib/spinner.ts +0 -93
  120. package/.claude/worktrees/emails-list/src/lib/table.ts +0 -57
  121. package/.claude/worktrees/emails-list/src/lib/tty.ts +0 -28
  122. package/.claude/worktrees/emails-list/src/lib/version.ts +0 -4
  123. package/.claude/worktrees/emails-list/tests/commands/api-keys/create.test.ts +0 -195
  124. package/.claude/worktrees/emails-list/tests/commands/api-keys/delete.test.ts +0 -156
  125. package/.claude/worktrees/emails-list/tests/commands/api-keys/list.test.ts +0 -133
  126. package/.claude/worktrees/emails-list/tests/commands/auth/login.test.ts +0 -119
  127. package/.claude/worktrees/emails-list/tests/commands/auth/logout.test.ts +0 -146
  128. package/.claude/worktrees/emails-list/tests/commands/broadcasts/create.test.ts +0 -447
  129. package/.claude/worktrees/emails-list/tests/commands/broadcasts/delete.test.ts +0 -182
  130. package/.claude/worktrees/emails-list/tests/commands/broadcasts/get.test.ts +0 -146
  131. package/.claude/worktrees/emails-list/tests/commands/broadcasts/list.test.ts +0 -196
  132. package/.claude/worktrees/emails-list/tests/commands/broadcasts/send.test.ts +0 -161
  133. package/.claude/worktrees/emails-list/tests/commands/broadcasts/update.test.ts +0 -283
  134. package/.claude/worktrees/emails-list/tests/commands/contact-properties/create.test.ts +0 -250
  135. package/.claude/worktrees/emails-list/tests/commands/contact-properties/delete.test.ts +0 -183
  136. package/.claude/worktrees/emails-list/tests/commands/contact-properties/get.test.ts +0 -144
  137. package/.claude/worktrees/emails-list/tests/commands/contact-properties/list.test.ts +0 -180
  138. package/.claude/worktrees/emails-list/tests/commands/contact-properties/update.test.ts +0 -216
  139. package/.claude/worktrees/emails-list/tests/commands/contacts/add-segment.test.ts +0 -188
  140. package/.claude/worktrees/emails-list/tests/commands/contacts/create.test.ts +0 -270
  141. package/.claude/worktrees/emails-list/tests/commands/contacts/delete.test.ts +0 -192
  142. package/.claude/worktrees/emails-list/tests/commands/contacts/get.test.ts +0 -148
  143. package/.claude/worktrees/emails-list/tests/commands/contacts/list.test.ts +0 -175
  144. package/.claude/worktrees/emails-list/tests/commands/contacts/remove-segment.test.ts +0 -166
  145. package/.claude/worktrees/emails-list/tests/commands/contacts/segments.test.ts +0 -167
  146. package/.claude/worktrees/emails-list/tests/commands/contacts/topics.test.ts +0 -163
  147. package/.claude/worktrees/emails-list/tests/commands/contacts/update-topics.test.ts +0 -247
  148. package/.claude/worktrees/emails-list/tests/commands/contacts/update.test.ts +0 -205
  149. package/.claude/worktrees/emails-list/tests/commands/doctor.test.ts +0 -165
  150. package/.claude/worktrees/emails-list/tests/commands/domains/create.test.ts +0 -192
  151. package/.claude/worktrees/emails-list/tests/commands/domains/delete.test.ts +0 -156
  152. package/.claude/worktrees/emails-list/tests/commands/domains/get.test.ts +0 -137
  153. package/.claude/worktrees/emails-list/tests/commands/domains/list.test.ts +0 -164
  154. package/.claude/worktrees/emails-list/tests/commands/domains/update.test.ts +0 -223
  155. package/.claude/worktrees/emails-list/tests/commands/domains/verify.test.ts +0 -117
  156. package/.claude/worktrees/emails-list/tests/commands/emails/batch.test.ts +0 -313
  157. package/.claude/worktrees/emails-list/tests/commands/emails/list.test.ts +0 -196
  158. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachment.test.ts +0 -140
  159. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachments.test.ts +0 -168
  160. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/get.test.ts +0 -140
  161. package/.claude/worktrees/emails-list/tests/commands/emails/receiving/list.test.ts +0 -181
  162. package/.claude/worktrees/emails-list/tests/commands/emails/send.test.ts +0 -309
  163. package/.claude/worktrees/emails-list/tests/commands/segments/create.test.ts +0 -163
  164. package/.claude/worktrees/emails-list/tests/commands/segments/delete.test.ts +0 -182
  165. package/.claude/worktrees/emails-list/tests/commands/segments/get.test.ts +0 -137
  166. package/.claude/worktrees/emails-list/tests/commands/segments/list.test.ts +0 -173
  167. package/.claude/worktrees/emails-list/tests/commands/teams/list.test.ts +0 -63
  168. package/.claude/worktrees/emails-list/tests/commands/teams/remove.test.ts +0 -103
  169. package/.claude/worktrees/emails-list/tests/commands/teams/switch.test.ts +0 -96
  170. package/.claude/worktrees/emails-list/tests/commands/topics/create.test.ts +0 -191
  171. package/.claude/worktrees/emails-list/tests/commands/topics/delete.test.ts +0 -156
  172. package/.claude/worktrees/emails-list/tests/commands/topics/get.test.ts +0 -125
  173. package/.claude/worktrees/emails-list/tests/commands/topics/list.test.ts +0 -124
  174. package/.claude/worktrees/emails-list/tests/commands/topics/update.test.ts +0 -177
  175. package/.claude/worktrees/emails-list/tests/commands/webhooks/create.test.ts +0 -224
  176. package/.claude/worktrees/emails-list/tests/commands/webhooks/delete.test.ts +0 -156
  177. package/.claude/worktrees/emails-list/tests/commands/webhooks/get.test.ts +0 -125
  178. package/.claude/worktrees/emails-list/tests/commands/webhooks/list.test.ts +0 -177
  179. package/.claude/worktrees/emails-list/tests/commands/webhooks/update.test.ts +0 -206
  180. package/.claude/worktrees/emails-list/tests/commands/whoami.test.ts +0 -99
  181. package/.claude/worktrees/emails-list/tests/helpers.ts +0 -93
  182. package/.claude/worktrees/emails-list/tests/lib/client.test.ts +0 -71
  183. package/.claude/worktrees/emails-list/tests/lib/config.test.ts +0 -414
  184. package/.claude/worktrees/emails-list/tests/lib/files.test.ts +0 -65
  185. package/.claude/worktrees/emails-list/tests/lib/help-text.test.ts +0 -97
  186. package/.claude/worktrees/emails-list/tests/lib/output.test.ts +0 -127
  187. package/.claude/worktrees/emails-list/tests/lib/prompts.test.ts +0 -178
  188. package/.claude/worktrees/emails-list/tests/lib/spinner.test.ts +0 -146
  189. package/.claude/worktrees/emails-list/tests/lib/table.test.ts +0 -63
  190. package/.claude/worktrees/emails-list/tests/lib/tty.test.ts +0 -85
  191. package/.claude/worktrees/emails-list/tsconfig.json +0 -14
@@ -1,68 +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 { renderContactPropertiesTable } from './utils';
11
-
12
- export const listContactPropertiesCommand = new Command('list')
13
- .alias('ls')
14
- .description('List all contact property definitions')
15
- .option(
16
- '--limit <n>',
17
- 'Maximum number of contact properties to return (1-100)',
18
- '10',
19
- )
20
- .option(
21
- '--after <cursor>',
22
- 'Return contact properties after this cursor (next page)',
23
- )
24
- .option(
25
- '--before <cursor>',
26
- 'Return contact properties before this cursor (previous page)',
27
- )
28
- .addHelpText(
29
- 'after',
30
- buildHelpText({
31
- context: `Pagination: use --after or --before with a contact property ID as the cursor.
32
- Only one of --after or --before may be used at a time.
33
- The response includes has_more: true when additional pages exist.`,
34
- output: ` {
35
- "object": "list",
36
- "has_more": false,
37
- "data": [
38
- { "id": "<uuid>", "key": "company_name", "type": "string", "fallbackValue": null, "createdAt": "..." }
39
- ]
40
- }`,
41
- errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
42
- examples: [
43
- 'resend contact-properties list',
44
- 'resend contact-properties list --limit 25 --json',
45
- 'resend contact-properties list --after b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --json',
46
- ],
47
- }),
48
- )
49
- .action(async (opts, cmd) => {
50
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
51
- const limit = parseLimitOpt(opts.limit, globalOpts);
52
- const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
53
- await runList(
54
- {
55
- spinner: {
56
- loading: 'Fetching contact properties...',
57
- success: 'Contact properties fetched',
58
- fail: 'Failed to list contact properties',
59
- },
60
- sdkCall: (resend) => resend.contactProperties.list(paginationOpts),
61
- onInteractive: (list) => {
62
- console.log(renderContactPropertiesTable(list.data));
63
- printPaginationHint(list);
64
- },
65
- },
66
- globalOpts,
67
- );
68
- });
@@ -1,88 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { runWrite } from '../../lib/actions';
3
- import type { GlobalOpts } from '../../lib/client';
4
- import { buildHelpText } from '../../lib/help-text';
5
- import { outputError } from '../../lib/output';
6
-
7
- export const updateContactPropertyCommand = new Command('update')
8
- .description('Update a contact property definition')
9
- .argument('<id>', 'Contact property UUID')
10
- .option(
11
- '--fallback-value <value>',
12
- 'New fallback value used in broadcast templates when a contact has no value set for this property',
13
- )
14
- .option(
15
- '--clear-fallback-value',
16
- 'Remove the fallback value (sets it to null)',
17
- )
18
- .addHelpText(
19
- 'after',
20
- buildHelpText({
21
- context: `Note: the property key and type cannot be changed after creation. Only the fallback value
22
- is updatable. Renaming a property would break existing broadcasts that reference the old key.
23
-
24
- --fallback-value and --clear-fallback-value are mutually exclusive.
25
-
26
- The fallback value is used in broadcast template interpolation when a contact has no value:
27
- {{{company_name|Unknown}}} — inline fallback (takes precedence over the property's fallback)
28
- {{{company_name}}} — uses the property's stored fallback value if set`,
29
- output: ` {"object":"contact_property","id":"<id>"}`,
30
- errorCodes: [
31
- 'auth_error',
32
- 'no_changes',
33
- 'conflicting_flags',
34
- 'update_error',
35
- ],
36
- examples: [
37
- 'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value "Acme Corp"',
38
- 'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value 42',
39
- 'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --clear-fallback-value',
40
- 'resend contact-properties update b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d --fallback-value "Unknown" --json',
41
- ],
42
- }),
43
- )
44
- .action(async (id, opts, cmd) => {
45
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
46
-
47
- if (opts.fallbackValue === undefined && !opts.clearFallbackValue) {
48
- outputError(
49
- {
50
- message:
51
- 'Provide at least one option to update: --fallback-value or --clear-fallback-value.',
52
- code: 'no_changes',
53
- },
54
- { json: globalOpts.json },
55
- );
56
- }
57
-
58
- if (opts.fallbackValue !== undefined && opts.clearFallbackValue) {
59
- outputError(
60
- {
61
- message:
62
- '--fallback-value and --clear-fallback-value are mutually exclusive.',
63
- code: 'conflicting_flags',
64
- },
65
- { json: globalOpts.json },
66
- );
67
- }
68
-
69
- const fallbackValue = opts.clearFallbackValue ? null : opts.fallbackValue;
70
-
71
- await runWrite(
72
- {
73
- spinner: {
74
- loading: 'Updating contact property...',
75
- success: 'Contact property updated',
76
- fail: 'Failed to update contact property',
77
- },
78
- sdkCall: (resend) =>
79
- resend.contactProperties.update({
80
- id,
81
- ...(fallbackValue !== undefined && { fallbackValue }),
82
- }),
83
- errorCode: 'update_error',
84
- successMsg: `Contact property updated: ${id}`,
85
- },
86
- globalOpts,
87
- );
88
- });
@@ -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
- });