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,77 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import type { UpdateContactOptions } from 'resend';
3
- import { runWrite } from '../../lib/actions';
4
- import type { GlobalOpts } from '../../lib/client';
5
- import { buildHelpText } from '../../lib/help-text';
6
- import { contactIdentifier, parsePropertiesJson } from './utils';
7
-
8
- export const updateContactCommand = new Command('update')
9
- .description("Update a contact's subscription status or custom properties")
10
- .argument(
11
- '<id>',
12
- 'Contact UUID or email address — both are accepted by the API',
13
- )
14
- .option(
15
- '--unsubscribed',
16
- 'Globally unsubscribe the contact from all broadcasts',
17
- )
18
- .option(
19
- '--no-unsubscribed',
20
- 'Re-subscribe the contact (clears the global unsubscribe flag)',
21
- )
22
- .option(
23
- '--properties <json>',
24
- 'JSON object of properties to merge (e.g. \'{"company":"Acme"}\'); set a key to null to clear it',
25
- )
26
- .addHelpText(
27
- 'after',
28
- buildHelpText({
29
- context: `The <id> argument accepts either a UUID or an email address.
30
-
31
- Subscription toggle:
32
- --unsubscribed Sets unsubscribed: true — contact will not receive any broadcasts.
33
- --no-unsubscribed Sets unsubscribed: false — re-enables broadcast delivery.
34
- Omitting both flags leaves the subscription status unchanged.
35
-
36
- Properties: --properties merges the given JSON object with existing properties.
37
- Set a key to null to clear it: '{"company":null}'.`,
38
- output: ` {"object":"contact","id":"<id>"}`,
39
- errorCodes: ['auth_error', 'invalid_properties', 'update_error'],
40
- examples: [
41
- 'resend contacts update 479e3145-dd38-4932-8c0c-e58b548c9e76 --unsubscribed',
42
- 'resend contacts update user@example.com --no-unsubscribed',
43
- `resend contacts update 479e3145-dd38-4932-8c0c-e58b548c9e76 --properties '{"plan":"pro"}'`,
44
- 'resend contacts update user@example.com --unsubscribed --json',
45
- ],
46
- }),
47
- )
48
- .action(async (id, opts, cmd) => {
49
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
50
-
51
- const properties = parsePropertiesJson(opts.properties, globalOpts);
52
-
53
- // contactIdentifier resolves UUID vs email. The spread of a discriminated
54
- // union requires an explicit cast because TypeScript cannot narrow it
55
- // through a spread at the call site.
56
- const payload = {
57
- ...contactIdentifier(id),
58
- ...(opts.unsubscribed !== undefined && {
59
- unsubscribed: opts.unsubscribed,
60
- }),
61
- ...(properties && { properties }),
62
- } as UpdateContactOptions;
63
-
64
- await runWrite(
65
- {
66
- spinner: {
67
- loading: 'Updating contact...',
68
- success: 'Contact updated',
69
- fail: 'Failed to update contact',
70
- },
71
- sdkCall: (resend) => resend.contacts.update(payload),
72
- errorCode: 'update_error',
73
- successMsg: `Contact updated: ${id}`,
74
- },
75
- globalOpts,
76
- );
77
- });
@@ -1,119 +0,0 @@
1
- import type { ContactSegmentsBaseOptions, ContactTopic } from 'resend';
2
- import type { GlobalOpts } from '../../lib/client';
3
- import { outputError } from '../../lib/output';
4
- import { renderTable } from '../../lib/table';
5
-
6
- // ─── Table renderers ─────────────────────────────────────────────────────────
7
-
8
- export function renderContactsTable(
9
- contacts: Array<{
10
- id: string;
11
- email: string;
12
- first_name: string | null;
13
- last_name: string | null;
14
- unsubscribed: boolean;
15
- }>,
16
- ): string {
17
- const rows = contacts.map((c) => [
18
- c.email,
19
- c.first_name ?? '',
20
- c.last_name ?? '',
21
- c.unsubscribed ? 'yes' : 'no',
22
- c.id,
23
- ]);
24
- return renderTable(
25
- ['Email', 'First Name', 'Last Name', 'Unsubscribed', 'ID'],
26
- rows,
27
- '(no contacts)',
28
- );
29
- }
30
-
31
- export function renderContactTopicsTable(topics: ContactTopic[]): string {
32
- const rows = topics.map((t) => [
33
- t.name,
34
- t.subscription,
35
- t.id,
36
- t.description ?? '',
37
- ]);
38
- return renderTable(
39
- ['Name', 'Subscription', 'ID', 'Description'],
40
- rows,
41
- '(no topic subscriptions)',
42
- );
43
- }
44
-
45
- // ─── Contact identifier helpers ───────────────────────────────────────────────
46
- //
47
- // The Resend SDK uses two different discriminated-union shapes depending on
48
- // the API surface:
49
- //
50
- // • contactIdentifier — produces { id } | { email } for endpoints that
51
- // accept SelectingField (update, get, remove) or { id?, email? }
52
- // (topics list/update).
53
- //
54
- // • segmentContactIdentifier — produces { contactId } | { email } for the
55
- // contacts.segments.* endpoints, which use ContactSegmentsBaseOptions.
56
- //
57
- // Centralising the `str.includes('@')` check here prevents it from drifting
58
- // across six separate command files.
59
-
60
- export function contactIdentifier(
61
- id: string,
62
- ): { id: string } | { email: string } {
63
- return id.includes('@') ? { email: id } : { id };
64
- }
65
-
66
- export function segmentContactIdentifier(
67
- id: string,
68
- ): ContactSegmentsBaseOptions {
69
- return id.includes('@') ? { email: id } : { contactId: id };
70
- }
71
-
72
- // ─── JSON flag helpers ────────────────────────────────────────────────────────
73
-
74
- export function parseTopicsJson(
75
- raw: string,
76
- globalOpts: GlobalOpts,
77
- ): Array<{ id: string; subscription: 'opt_in' | 'opt_out' }> {
78
- let parsed: unknown;
79
- try {
80
- parsed = JSON.parse(raw);
81
- } catch {
82
- outputError(
83
- {
84
- message:
85
- 'Invalid --topics JSON. Expected an array of {id, subscription} objects.',
86
- code: 'invalid_topics',
87
- },
88
- { json: globalOpts.json },
89
- );
90
- }
91
- if (!Array.isArray(parsed)) {
92
- outputError(
93
- {
94
- message:
95
- 'Invalid --topics JSON. Expected an array of {id, subscription} objects.',
96
- code: 'invalid_topics',
97
- },
98
- { json: globalOpts.json },
99
- );
100
- }
101
- return parsed as Array<{ id: string; subscription: 'opt_in' | 'opt_out' }>;
102
- }
103
-
104
- export function parsePropertiesJson(
105
- raw: string | undefined,
106
- globalOpts: GlobalOpts,
107
- ): Record<string, string | number | null> | undefined {
108
- if (!raw) {
109
- return undefined;
110
- }
111
- try {
112
- return JSON.parse(raw) as Record<string, string | number | null>;
113
- } catch {
114
- outputError(
115
- { message: 'Invalid --properties JSON.', code: 'invalid_properties' },
116
- { json: globalOpts.json },
117
- );
118
- }
119
- }
@@ -1,216 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { Resend } from 'resend';
3
- import type { GlobalOpts } from '../lib/client';
4
- import { maskKey, resolveApiKey } from '../lib/config';
5
- import { buildHelpText } from '../lib/help-text';
6
- import { errorMessage, outputResult } from '../lib/output';
7
- import { createSpinner } from '../lib/spinner';
8
- import { isInteractive } from '../lib/tty';
9
- import { GITHUB_RELEASES_URL } from '../lib/update-check';
10
- import { VERSION } from '../lib/version';
11
-
12
- type CheckStatus = 'pass' | 'warn' | 'fail';
13
-
14
- type CheckResult = {
15
- name: string;
16
- status: CheckStatus;
17
- message: string;
18
- detail?: string;
19
- };
20
-
21
- async function checkCliVersion(): Promise<CheckResult> {
22
- try {
23
- const res = await fetch(GITHUB_RELEASES_URL, {
24
- headers: { Accept: 'application/vnd.github.v3+json' },
25
- signal: AbortSignal.timeout(5000),
26
- });
27
- if (!res.ok) {
28
- return {
29
- name: 'CLI Version',
30
- status: 'warn',
31
- message: `v${VERSION} (could not check for updates)`,
32
- };
33
- }
34
- const data = (await res.json()) as {
35
- tag_name?: string;
36
- prerelease?: boolean;
37
- draft?: boolean;
38
- };
39
- if (data.prerelease || data.draft) {
40
- return {
41
- name: 'CLI Version',
42
- status: 'warn',
43
- message: `v${VERSION} (could not check for updates)`,
44
- };
45
- }
46
- const latest = data.tag_name?.replace(/^v/, '') ?? 'unknown';
47
- if (latest === VERSION) {
48
- return {
49
- name: 'CLI Version',
50
- status: 'pass',
51
- message: `v${VERSION} (latest)`,
52
- };
53
- }
54
- return {
55
- name: 'CLI Version',
56
- status: 'warn',
57
- message: `v${VERSION} (latest: v${latest})`,
58
- detail: 'Update available',
59
- };
60
- } catch {
61
- return {
62
- name: 'CLI Version',
63
- status: 'warn',
64
- message: `v${VERSION} (could not check for updates)`,
65
- };
66
- }
67
- }
68
-
69
- function checkApiKeyPresence(flagValue?: string): CheckResult {
70
- const resolved = resolveApiKey(flagValue);
71
- if (!resolved) {
72
- return {
73
- name: 'API Key',
74
- status: 'fail',
75
- message: 'No API key found',
76
- detail: 'Run: resend login',
77
- };
78
- }
79
- const teamInfo = resolved.team ? `, team: ${resolved.team}` : '';
80
- return {
81
- name: 'API Key',
82
- status: 'pass',
83
- message: `${maskKey(resolved.key)} (source: ${resolved.source}${teamInfo})`,
84
- };
85
- }
86
-
87
- async function checkApiValidationAndDomains(
88
- flagValue?: string,
89
- ): Promise<CheckResult> {
90
- const resolved = resolveApiKey(flagValue);
91
- if (!resolved) {
92
- return {
93
- name: 'API Validation',
94
- status: 'fail',
95
- message: 'Skipped — no API key',
96
- };
97
- }
98
-
99
- try {
100
- const resend = new Resend(resolved.key);
101
- const { data, error } = await resend.domains.list();
102
-
103
- if (error) {
104
- return {
105
- name: 'API Validation',
106
- status: 'fail',
107
- message: `API key invalid: ${error.message}`,
108
- };
109
- }
110
-
111
- const domains = data?.data ?? [];
112
- const verified = domains.filter((d) => d.status === 'verified');
113
- const pending = domains.filter((d) => d.status !== 'verified');
114
-
115
- if (domains.length === 0) {
116
- return {
117
- name: 'Domains',
118
- status: 'warn',
119
- message: 'No domains configured',
120
- detail: 'Add a domain at https://resend.com/domains',
121
- };
122
- }
123
-
124
- if (verified.length === 0) {
125
- return {
126
- name: 'Domains',
127
- status: 'warn',
128
- message: `${pending.length} domain(s) pending verification`,
129
- detail: domains.map((d) => `${d.name} (${d.status})`).join(', '),
130
- };
131
- }
132
-
133
- return {
134
- name: 'Domains',
135
- status: 'pass',
136
- message: `${verified.length} verified, ${pending.length} pending`,
137
- detail: domains.map((d) => `${d.name} (${d.status})`).join(', '),
138
- };
139
- } catch (err) {
140
- return {
141
- name: 'API Validation',
142
- status: 'fail',
143
- message: errorMessage(err, 'Failed to validate API key'),
144
- };
145
- }
146
- }
147
-
148
- export const doctorCommand = new Command('doctor')
149
- .description('Check CLI version, API key, and domain status')
150
- .addHelpText(
151
- 'after',
152
- buildHelpText({
153
- setup: true,
154
- context: `Checks performed:
155
- CLI Version Is the installed version up to date?
156
- API Key Is a key present (--api-key, RESEND_API_KEY, or credentials file)?
157
- API Validation Is the key valid and accepted by the Resend API?`,
158
- output: ` {\n "ok": true,\n "checks": [\n {"name":"CLI Version","status":"pass","message":"v0.1.0 (latest)"},\n {"name":"API Key","status":"pass","message":"re_...abcd (source: env)"},\n {"name":"Domains","status":"pass","message":"1 verified, 0 pending"}\n ]\n }\n status values: "pass" | "warn" | "fail"\n Exit code 1 if any check has status "fail"`,
159
- examples: ['resend doctor', 'resend doctor --json'],
160
- }),
161
- )
162
- .action(async (_opts, cmd) => {
163
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
164
- const checks: CheckResult[] = [];
165
- const interactive = isInteractive() && !globalOpts.json;
166
-
167
- if (interactive) {
168
- console.log('\n Resend Doctor\n');
169
- }
170
-
171
- // Check 1: CLI Version
172
- let spinner = interactive ? createSpinner('Checking CLI version...') : null;
173
- const versionCheck = await checkCliVersion();
174
- checks.push(versionCheck);
175
- if (versionCheck.status === 'warn') {
176
- spinner?.warn(versionCheck.message);
177
- } else {
178
- spinner?.stop(versionCheck.message);
179
- }
180
-
181
- // Check 2: API Key
182
- spinner = interactive ? createSpinner('Checking API key...') : null;
183
- const keyCheck = checkApiKeyPresence(globalOpts.apiKey);
184
- checks.push(keyCheck);
185
- if (keyCheck.status === 'fail') {
186
- spinner?.fail(keyCheck.message);
187
- } else {
188
- spinner?.stop(keyCheck.message);
189
- }
190
-
191
- // Check 3: API Validation + Domains
192
- spinner = interactive
193
- ? createSpinner('Validating API key & domains...')
194
- : null;
195
- const domainCheck = await checkApiValidationAndDomains(globalOpts.apiKey);
196
- checks.push(domainCheck);
197
- if (domainCheck.status === 'fail') {
198
- spinner?.fail(domainCheck.message);
199
- } else if (domainCheck.status === 'warn') {
200
- spinner?.warn(domainCheck.message);
201
- } else {
202
- spinner?.stop(domainCheck.message);
203
- }
204
-
205
- const hasFails = checks.some((c) => c.status === 'fail');
206
-
207
- if (!globalOpts.json && isInteractive()) {
208
- console.log('');
209
- } else {
210
- outputResult({ ok: !hasFails, checks }, { json: globalOpts.json });
211
- }
212
-
213
- if (hasFails) {
214
- process.exit(1);
215
- }
216
- });
@@ -1,83 +0,0 @@
1
- import { Command, Option } from '@commander-js/extra-typings';
2
- import { runCreate } from '../../lib/actions';
3
- import type { GlobalOpts } from '../../lib/client';
4
- import { buildHelpText } from '../../lib/help-text';
5
- import { requireText } from '../../lib/prompts';
6
- import { renderDnsRecordsTable } from './utils';
7
-
8
- export const createDomainCommand = new Command('create')
9
- .description('Create a new domain and receive DNS records to configure')
10
- .option('--name <domain>', 'Domain name (e.g. example.com)')
11
- .addOption(
12
- new Option('--region <region>', 'Sending region').choices([
13
- 'us-east-1',
14
- 'eu-west-1',
15
- 'sa-east-1',
16
- 'ap-northeast-1',
17
- ] as const),
18
- )
19
- .addOption(
20
- new Option('--tls <mode>', 'TLS mode (default: opportunistic)').choices([
21
- 'opportunistic',
22
- 'enforced',
23
- ] as const),
24
- )
25
- .option('--sending', 'Enable sending capability (default: enabled)')
26
- .option('--receiving', 'Enable receiving capability (default: disabled)')
27
- .addHelpText(
28
- 'after',
29
- buildHelpText({
30
- context:
31
- 'Non-interactive: --name is required (no prompts when stdin/stdout is not a TTY)',
32
- output:
33
- ' Full domain object with DNS records array to configure in your DNS provider.',
34
- errorCodes: ['auth_error', 'missing_name', 'create_error'],
35
- examples: [
36
- 'resend domains create --name example.com',
37
- 'resend domains create --name example.com --region eu-west-1 --tls enforced',
38
- 'resend domains create --name example.com --receiving --json',
39
- 'resend domains create --name example.com --sending --receiving --json',
40
- ],
41
- }),
42
- )
43
- .action(async (opts, cmd) => {
44
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
45
-
46
- const name = await requireText(
47
- opts.name,
48
- { message: 'Domain name', placeholder: 'example.com' },
49
- { message: 'Missing --name flag.', code: 'missing_name' },
50
- globalOpts,
51
- );
52
-
53
- await runCreate(
54
- {
55
- spinner: {
56
- loading: 'Creating domain...',
57
- success: 'Domain created',
58
- fail: 'Failed to create domain',
59
- },
60
- sdkCall: (resend) =>
61
- resend.domains.create({
62
- name,
63
- ...(opts.region && { region: opts.region }),
64
- ...(opts.tls && { tls: opts.tls }),
65
- ...((opts.sending || opts.receiving) && {
66
- capabilities: {
67
- ...(opts.sending && { sending: 'enabled' as const }),
68
- ...(opts.receiving && { receiving: 'enabled' as const }),
69
- },
70
- }),
71
- }),
72
- onInteractive: (d) => {
73
- console.log(`\nDomain created: ${d.name} (id: ${d.id})`);
74
- console.log('\nDNS Records to configure:');
75
- console.log(renderDnsRecordsTable(d.records, d.name));
76
- console.log(
77
- `\nRun \`resend domains verify ${d.id}\` after configuring DNS.`,
78
- );
79
- },
80
- },
81
- globalOpts,
82
- );
83
- });
@@ -1,42 +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 deleteDomainCommand = new Command('delete')
7
- .alias('rm')
8
- .description('Delete a domain')
9
- .argument('<id>', 'Domain ID')
10
- .option('--yes', 'Skip confirmation prompt')
11
- .addHelpText(
12
- 'after',
13
- buildHelpText({
14
- context:
15
- 'Non-interactive: --yes is required to confirm deletion when stdin/stdout is not a TTY.',
16
- output: ' {"object":"domain","id":"<id>","deleted":true}',
17
- errorCodes: ['auth_error', 'confirmation_required', 'delete_error'],
18
- examples: [
19
- 'resend domains delete 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --yes',
20
- 'resend domains delete 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --yes --json',
21
- ],
22
- }),
23
- )
24
- .action(async (id, opts, cmd) => {
25
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
26
- await runDelete(
27
- id,
28
- !!opts.yes,
29
- {
30
- confirmMessage: `Delete domain ${id}?\nThis cannot be undone.`,
31
- spinner: {
32
- loading: 'Deleting domain...',
33
- success: 'Domain deleted',
34
- fail: 'Failed to delete domain',
35
- },
36
- object: 'domain',
37
- successMsg: 'Domain deleted.',
38
- sdkCall: (resend) => resend.domains.remove(id),
39
- },
40
- globalOpts,
41
- );
42
- });
@@ -1,47 +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
- import { renderDnsRecordsTable, statusIndicator } from './utils';
6
-
7
- export const getDomainCommand = new Command('get')
8
- .description(
9
- 'Retrieve a domain with its DNS records and current verification status',
10
- )
11
- .argument('<id>', 'Domain ID')
12
- .addHelpText(
13
- 'after',
14
- buildHelpText({
15
- output:
16
- ' Full domain object including records array and current status.\n\nDomain status values: not_started | pending | verified | failed | temporary_failure',
17
- errorCodes: ['auth_error', 'fetch_error'],
18
- examples: [
19
- 'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
20
- 'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0 --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 domain...',
30
- success: 'Domain fetched',
31
- fail: 'Failed to fetch domain',
32
- },
33
- sdkCall: (resend) => resend.domains.get(id),
34
- onInteractive: (d) => {
35
- console.log(`\n${d.name} — ${statusIndicator(d.status)}`);
36
- console.log(`ID: ${d.id}`);
37
- console.log(`Region: ${d.region}`);
38
- console.log(`Created: ${d.created_at}`);
39
- if (d.records.length > 0) {
40
- console.log('\nDNS Records:');
41
- console.log(renderDnsRecordsTable(d.records, d.name));
42
- }
43
- },
44
- },
45
- globalOpts,
46
- );
47
- });
@@ -1,35 +0,0 @@
1
- import { Command } from '@commander-js/extra-typings';
2
- import { buildHelpText } from '../../lib/help-text';
3
- import { createDomainCommand } from './create';
4
- import { deleteDomainCommand } from './delete';
5
- import { getDomainCommand } from './get';
6
- import { listDomainsCommand } from './list';
7
- import { updateDomainCommand } from './update';
8
- import { verifyDomainCommand } from './verify';
9
-
10
- export const domainsCommand = new Command('domains')
11
- .description('Manage verified sending and receiving domains')
12
- .addHelpText(
13
- 'after',
14
- buildHelpText({
15
- context: `Domain lifecycle:
16
- 1. resend domains create --name example.com (get DNS records)
17
- 2. Configure DNS records at your DNS provider
18
- 3. resend domains verify <id> (trigger verification)
19
- 4. resend domains get <id> (poll until "verified")`,
20
- examples: [
21
- 'resend domains list',
22
- 'resend domains create --name example.com --region us-east-1',
23
- 'resend domains verify 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
24
- 'resend domains get 4dd369bc-aa82-4ff3-97de-514ae3000ee0',
25
- 'resend domains update <id> --tls enforced --open-tracking',
26
- 'resend domains delete <id> --yes',
27
- ],
28
- }),
29
- )
30
- .addCommand(createDomainCommand)
31
- .addCommand(verifyDomainCommand)
32
- .addCommand(getDomainCommand)
33
- .addCommand(listDomainsCommand, { isDefault: true })
34
- .addCommand(updateDomainCommand)
35
- .addCommand(deleteDomainCommand);
@@ -1,53 +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 { renderDomainsTable } from './utils';
11
-
12
- export const listDomainsCommand = new Command('list')
13
- .alias('ls')
14
- .description('List all domains')
15
- .option('--limit <n>', 'Maximum number of domains to return (1-100)', '10')
16
- .option('--after <cursor>', 'Return domains after this cursor (next page)')
17
- .option(
18
- '--before <cursor>',
19
- 'Return domains before this cursor (previous page)',
20
- )
21
- .addHelpText(
22
- 'after',
23
- buildHelpText({
24
- output:
25
- ' {"object":"list","data":[...],"has_more":true}\n The list response does not include DNS records — use "resend domains get <id>" for that.',
26
- errorCodes: ['auth_error', 'invalid_limit', 'list_error'],
27
- examples: [
28
- 'resend domains list',
29
- 'resend domains list --limit 25 --json',
30
- 'resend domains list --after <cursor> --json',
31
- ],
32
- }),
33
- )
34
- .action(async (opts, cmd) => {
35
- const globalOpts = cmd.optsWithGlobals() as GlobalOpts;
36
- const limit = parseLimitOpt(opts.limit, globalOpts);
37
- const paginationOpts = buildPaginationOpts(limit, opts.after, opts.before);
38
- await runList(
39
- {
40
- spinner: {
41
- loading: 'Fetching domains...',
42
- success: 'Domains fetched',
43
- fail: 'Failed to list domains',
44
- },
45
- sdkCall: (resend) => resend.domains.list(paginationOpts),
46
- onInteractive: (list) => {
47
- console.log(renderDomainsTable(list.data));
48
- printPaginationHint(list);
49
- },
50
- },
51
- globalOpts,
52
- );
53
- });