superacli 1.1.5 → 1.1.6

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/__tests__/resend-plugin.test.js +22 -1
  2. package/package.json +1 -1
  3. package/plugins/plugins.json +2 -2
  4. package/plugins/resend/plugin.json +279 -2
  5. package/plugins/resend/skills/quickstart/SKILL.md +32 -13
  6. package/temp_resend_cli/repo/.github/scripts/pr-title-check.js +34 -0
  7. package/temp_resend_cli/repo/.github/workflows/ci.yml +67 -0
  8. package/temp_resend_cli/repo/.github/workflows/post-release.yml +51 -0
  9. package/temp_resend_cli/repo/.github/workflows/pr-title-check.yml +13 -0
  10. package/temp_resend_cli/repo/.github/workflows/release.yml +175 -0
  11. package/temp_resend_cli/repo/.github/workflows/test-install-unix.yml +34 -0
  12. package/temp_resend_cli/repo/.github/workflows/test-install-windows.yml +48 -0
  13. package/temp_resend_cli/repo/CHANGELOG.md +31 -0
  14. package/temp_resend_cli/repo/LICENSE +21 -0
  15. package/temp_resend_cli/repo/README.md +450 -0
  16. package/temp_resend_cli/repo/biome.json +36 -0
  17. package/temp_resend_cli/repo/install.ps1 +141 -0
  18. package/temp_resend_cli/repo/install.sh +301 -0
  19. package/temp_resend_cli/repo/package.json +61 -0
  20. package/temp_resend_cli/repo/pnpm-lock.yaml +2439 -0
  21. package/temp_resend_cli/repo/renovate.json +4 -0
  22. package/temp_resend_cli/repo/src/cli.ts +98 -0
  23. package/temp_resend_cli/repo/src/commands/api-keys/create.ts +114 -0
  24. package/temp_resend_cli/repo/src/commands/api-keys/delete.ts +47 -0
  25. package/temp_resend_cli/repo/src/commands/api-keys/index.ts +26 -0
  26. package/temp_resend_cli/repo/src/commands/api-keys/list.ts +35 -0
  27. package/temp_resend_cli/repo/src/commands/api-keys/utils.ts +8 -0
  28. package/temp_resend_cli/repo/src/commands/auth/index.ts +20 -0
  29. package/temp_resend_cli/repo/src/commands/auth/login.ts +234 -0
  30. package/temp_resend_cli/repo/src/commands/auth/logout.ts +105 -0
  31. package/temp_resend_cli/repo/src/commands/broadcasts/create.ts +196 -0
  32. package/temp_resend_cli/repo/src/commands/broadcasts/delete.ts +46 -0
  33. package/temp_resend_cli/repo/src/commands/broadcasts/get.ts +59 -0
  34. package/temp_resend_cli/repo/src/commands/broadcasts/index.ts +43 -0
  35. package/temp_resend_cli/repo/src/commands/broadcasts/list.ts +60 -0
  36. package/temp_resend_cli/repo/src/commands/broadcasts/send.ts +56 -0
  37. package/temp_resend_cli/repo/src/commands/broadcasts/update.ts +95 -0
  38. package/temp_resend_cli/repo/src/commands/broadcasts/utils.ts +35 -0
  39. package/temp_resend_cli/repo/src/commands/contact-properties/create.ts +118 -0
  40. package/temp_resend_cli/repo/src/commands/contact-properties/delete.ts +48 -0
  41. package/temp_resend_cli/repo/src/commands/contact-properties/get.ts +46 -0
  42. package/temp_resend_cli/repo/src/commands/contact-properties/index.ts +48 -0
  43. package/temp_resend_cli/repo/src/commands/contact-properties/list.ts +68 -0
  44. package/temp_resend_cli/repo/src/commands/contact-properties/update.ts +88 -0
  45. package/temp_resend_cli/repo/src/commands/contact-properties/utils.ts +17 -0
  46. package/temp_resend_cli/repo/src/commands/contacts/add-segment.ts +78 -0
  47. package/temp_resend_cli/repo/src/commands/contacts/create.ts +122 -0
  48. package/temp_resend_cli/repo/src/commands/contacts/delete.ts +49 -0
  49. package/temp_resend_cli/repo/src/commands/contacts/get.ts +53 -0
  50. package/temp_resend_cli/repo/src/commands/contacts/index.ts +58 -0
  51. package/temp_resend_cli/repo/src/commands/contacts/list.ts +57 -0
  52. package/temp_resend_cli/repo/src/commands/contacts/remove-segment.ts +48 -0
  53. package/temp_resend_cli/repo/src/commands/contacts/segments.ts +39 -0
  54. package/temp_resend_cli/repo/src/commands/contacts/topics.ts +45 -0
  55. package/temp_resend_cli/repo/src/commands/contacts/update-topics.ts +90 -0
  56. package/temp_resend_cli/repo/src/commands/contacts/update.ts +77 -0
  57. package/temp_resend_cli/repo/src/commands/contacts/utils.ts +119 -0
  58. package/temp_resend_cli/repo/src/commands/doctor.ts +216 -0
  59. package/temp_resend_cli/repo/src/commands/domains/create.ts +83 -0
  60. package/temp_resend_cli/repo/src/commands/domains/delete.ts +42 -0
  61. package/temp_resend_cli/repo/src/commands/domains/get.ts +47 -0
  62. package/temp_resend_cli/repo/src/commands/domains/index.ts +35 -0
  63. package/temp_resend_cli/repo/src/commands/domains/list.ts +53 -0
  64. package/temp_resend_cli/repo/src/commands/domains/update.ts +75 -0
  65. package/temp_resend_cli/repo/src/commands/domains/utils.ts +44 -0
  66. package/temp_resend_cli/repo/src/commands/domains/verify.ts +38 -0
  67. package/temp_resend_cli/repo/src/commands/emails/batch.ts +140 -0
  68. package/temp_resend_cli/repo/src/commands/emails/get.ts +44 -0
  69. package/temp_resend_cli/repo/src/commands/emails/index.ts +30 -0
  70. package/temp_resend_cli/repo/src/commands/emails/list.ts +84 -0
  71. package/temp_resend_cli/repo/src/commands/emails/receiving/attachment.ts +55 -0
  72. package/temp_resend_cli/repo/src/commands/emails/receiving/attachments.ts +68 -0
  73. package/temp_resend_cli/repo/src/commands/emails/receiving/get.ts +58 -0
  74. package/temp_resend_cli/repo/src/commands/emails/receiving/index.ts +28 -0
  75. package/temp_resend_cli/repo/src/commands/emails/receiving/list.ts +59 -0
  76. package/temp_resend_cli/repo/src/commands/emails/receiving/utils.ts +38 -0
  77. package/temp_resend_cli/repo/src/commands/emails/send.ts +189 -0
  78. package/temp_resend_cli/repo/src/commands/open.ts +27 -0
  79. package/temp_resend_cli/repo/src/commands/segments/create.ts +50 -0
  80. package/temp_resend_cli/repo/src/commands/segments/delete.ts +47 -0
  81. package/temp_resend_cli/repo/src/commands/segments/get.ts +38 -0
  82. package/temp_resend_cli/repo/src/commands/segments/index.ts +36 -0
  83. package/temp_resend_cli/repo/src/commands/segments/list.ts +58 -0
  84. package/temp_resend_cli/repo/src/commands/segments/utils.ts +7 -0
  85. package/temp_resend_cli/repo/src/commands/teams/index.ts +10 -0
  86. package/temp_resend_cli/repo/src/commands/teams/list.ts +35 -0
  87. package/temp_resend_cli/repo/src/commands/teams/remove.ts +86 -0
  88. package/temp_resend_cli/repo/src/commands/teams/switch.ts +76 -0
  89. package/temp_resend_cli/repo/src/commands/topics/create.ts +73 -0
  90. package/temp_resend_cli/repo/src/commands/topics/delete.ts +47 -0
  91. package/temp_resend_cli/repo/src/commands/topics/get.ts +42 -0
  92. package/temp_resend_cli/repo/src/commands/topics/index.ts +42 -0
  93. package/temp_resend_cli/repo/src/commands/topics/list.ts +34 -0
  94. package/temp_resend_cli/repo/src/commands/topics/update.ts +59 -0
  95. package/temp_resend_cli/repo/src/commands/topics/utils.ts +16 -0
  96. package/temp_resend_cli/repo/src/commands/webhooks/create.ts +128 -0
  97. package/temp_resend_cli/repo/src/commands/webhooks/delete.ts +49 -0
  98. package/temp_resend_cli/repo/src/commands/webhooks/get.ts +42 -0
  99. package/temp_resend_cli/repo/src/commands/webhooks/index.ts +42 -0
  100. package/temp_resend_cli/repo/src/commands/webhooks/list.ts +55 -0
  101. package/temp_resend_cli/repo/src/commands/webhooks/listen.ts +379 -0
  102. package/temp_resend_cli/repo/src/commands/webhooks/update.ts +83 -0
  103. package/temp_resend_cli/repo/src/commands/webhooks/utils.ts +36 -0
  104. package/temp_resend_cli/repo/src/commands/whoami.ts +71 -0
  105. package/temp_resend_cli/repo/src/lib/actions.ts +157 -0
  106. package/temp_resend_cli/repo/src/lib/client.ts +37 -0
  107. package/temp_resend_cli/repo/src/lib/config.ts +217 -0
  108. package/temp_resend_cli/repo/src/lib/files.ts +15 -0
  109. package/temp_resend_cli/repo/src/lib/help-text.ts +38 -0
  110. package/temp_resend_cli/repo/src/lib/output.ts +56 -0
  111. package/temp_resend_cli/repo/src/lib/pagination.ts +36 -0
  112. package/temp_resend_cli/repo/src/lib/prompts.ts +149 -0
  113. package/temp_resend_cli/repo/src/lib/spinner.ts +100 -0
  114. package/temp_resend_cli/repo/src/lib/table.ts +57 -0
  115. package/temp_resend_cli/repo/src/lib/tty.ts +28 -0
  116. package/temp_resend_cli/repo/src/lib/update-check.ts +169 -0
  117. package/temp_resend_cli/repo/src/lib/version.ts +4 -0
  118. package/temp_resend_cli/repo/tests/commands/api-keys/create.test.ts +196 -0
  119. package/temp_resend_cli/repo/tests/commands/api-keys/delete.test.ts +157 -0
  120. package/temp_resend_cli/repo/tests/commands/api-keys/list.test.ts +134 -0
  121. package/temp_resend_cli/repo/tests/commands/auth/login.test.ts +153 -0
  122. package/temp_resend_cli/repo/tests/commands/auth/logout.test.ts +153 -0
  123. package/temp_resend_cli/repo/tests/commands/broadcasts/create.test.ts +454 -0
  124. package/temp_resend_cli/repo/tests/commands/broadcasts/delete.test.ts +183 -0
  125. package/temp_resend_cli/repo/tests/commands/broadcasts/get.test.ts +147 -0
  126. package/temp_resend_cli/repo/tests/commands/broadcasts/list.test.ts +199 -0
  127. package/temp_resend_cli/repo/tests/commands/broadcasts/send.test.ts +162 -0
  128. package/temp_resend_cli/repo/tests/commands/broadcasts/update.test.ts +288 -0
  129. package/temp_resend_cli/repo/tests/commands/contact-properties/create.test.ts +251 -0
  130. package/temp_resend_cli/repo/tests/commands/contact-properties/delete.test.ts +184 -0
  131. package/temp_resend_cli/repo/tests/commands/contact-properties/get.test.ts +145 -0
  132. package/temp_resend_cli/repo/tests/commands/contact-properties/list.test.ts +181 -0
  133. package/temp_resend_cli/repo/tests/commands/contact-properties/update.test.ts +217 -0
  134. package/temp_resend_cli/repo/tests/commands/contacts/add-segment.test.ts +189 -0
  135. package/temp_resend_cli/repo/tests/commands/contacts/create.test.ts +271 -0
  136. package/temp_resend_cli/repo/tests/commands/contacts/delete.test.ts +193 -0
  137. package/temp_resend_cli/repo/tests/commands/contacts/get.test.ts +149 -0
  138. package/temp_resend_cli/repo/tests/commands/contacts/list.test.ts +176 -0
  139. package/temp_resend_cli/repo/tests/commands/contacts/remove-segment.test.ts +167 -0
  140. package/temp_resend_cli/repo/tests/commands/contacts/segments.test.ts +168 -0
  141. package/temp_resend_cli/repo/tests/commands/contacts/topics.test.ts +164 -0
  142. package/temp_resend_cli/repo/tests/commands/contacts/update-topics.test.ts +248 -0
  143. package/temp_resend_cli/repo/tests/commands/contacts/update.test.ts +206 -0
  144. package/temp_resend_cli/repo/tests/commands/doctor.test.ts +164 -0
  145. package/temp_resend_cli/repo/tests/commands/domains/create.test.ts +193 -0
  146. package/temp_resend_cli/repo/tests/commands/domains/delete.test.ts +157 -0
  147. package/temp_resend_cli/repo/tests/commands/domains/get.test.ts +138 -0
  148. package/temp_resend_cli/repo/tests/commands/domains/list.test.ts +165 -0
  149. package/temp_resend_cli/repo/tests/commands/domains/update.test.ts +224 -0
  150. package/temp_resend_cli/repo/tests/commands/domains/verify.test.ts +118 -0
  151. package/temp_resend_cli/repo/tests/commands/emails/batch.test.ts +324 -0
  152. package/temp_resend_cli/repo/tests/commands/emails/get.test.ts +132 -0
  153. package/temp_resend_cli/repo/tests/commands/emails/receiving/attachment.test.ts +141 -0
  154. package/temp_resend_cli/repo/tests/commands/emails/receiving/attachments.test.ts +169 -0
  155. package/temp_resend_cli/repo/tests/commands/emails/receiving/get.test.ts +141 -0
  156. package/temp_resend_cli/repo/tests/commands/emails/receiving/list.test.ts +182 -0
  157. package/temp_resend_cli/repo/tests/commands/emails/send.test.ts +312 -0
  158. package/temp_resend_cli/repo/tests/commands/segments/create.test.ts +164 -0
  159. package/temp_resend_cli/repo/tests/commands/segments/delete.test.ts +183 -0
  160. package/temp_resend_cli/repo/tests/commands/segments/get.test.ts +138 -0
  161. package/temp_resend_cli/repo/tests/commands/segments/list.test.ts +174 -0
  162. package/temp_resend_cli/repo/tests/commands/teams/list.test.ts +62 -0
  163. package/temp_resend_cli/repo/tests/commands/teams/remove.test.ts +110 -0
  164. package/temp_resend_cli/repo/tests/commands/teams/switch.test.ts +103 -0
  165. package/temp_resend_cli/repo/tests/commands/topics/create.test.ts +192 -0
  166. package/temp_resend_cli/repo/tests/commands/topics/delete.test.ts +157 -0
  167. package/temp_resend_cli/repo/tests/commands/topics/get.test.ts +126 -0
  168. package/temp_resend_cli/repo/tests/commands/topics/list.test.ts +125 -0
  169. package/temp_resend_cli/repo/tests/commands/topics/update.test.ts +178 -0
  170. package/temp_resend_cli/repo/tests/commands/webhooks/create.test.ts +225 -0
  171. package/temp_resend_cli/repo/tests/commands/webhooks/delete.test.ts +157 -0
  172. package/temp_resend_cli/repo/tests/commands/webhooks/get.test.ts +126 -0
  173. package/temp_resend_cli/repo/tests/commands/webhooks/list.test.ts +178 -0
  174. package/temp_resend_cli/repo/tests/commands/webhooks/update.test.ts +207 -0
  175. package/temp_resend_cli/repo/tests/commands/whoami.test.ts +98 -0
  176. package/temp_resend_cli/repo/tests/e2e/smoke.test.ts +93 -0
  177. package/temp_resend_cli/repo/tests/helpers.ts +86 -0
  178. package/temp_resend_cli/repo/tests/lib/client.test.ts +71 -0
  179. package/temp_resend_cli/repo/tests/lib/config.test.ts +451 -0
  180. package/temp_resend_cli/repo/tests/lib/files.test.ts +73 -0
  181. package/temp_resend_cli/repo/tests/lib/help-text.test.ts +97 -0
  182. package/temp_resend_cli/repo/tests/lib/output.test.ts +136 -0
  183. package/temp_resend_cli/repo/tests/lib/prompts.test.ts +185 -0
  184. package/temp_resend_cli/repo/tests/lib/spinner.test.ts +166 -0
  185. package/temp_resend_cli/repo/tests/lib/table.test.ts +63 -0
  186. package/temp_resend_cli/repo/tests/lib/tty.test.ts +89 -0
  187. package/temp_resend_cli/repo/tests/lib/update-check.test.ts +179 -0
  188. package/temp_resend_cli/repo/tsconfig.json +14 -0
  189. package/temp_resend_cli/repo/vitest.config.e2e.ts +8 -0
  190. package/temp_resend_cli/repo/vitest.config.ts +10 -0
  191. package/tests/test-resend-smoke.sh +7 -3
@@ -0,0 +1,312 @@
1
+ import { unlinkSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import {
5
+ afterEach,
6
+ beforeEach,
7
+ describe,
8
+ expect,
9
+ type MockInstance,
10
+ test,
11
+ vi,
12
+ } from 'vitest';
13
+ import {
14
+ captureTestEnv,
15
+ expectExit1,
16
+ mockExitThrow,
17
+ setNonInteractive,
18
+ setupOutputSpies,
19
+ } from '../../helpers';
20
+
21
+ const mockSend = vi.fn(async () => ({
22
+ data: { id: 'test-email-id-123' },
23
+ error: null,
24
+ }));
25
+
26
+ const mockDomainsList = vi.fn(async () => ({
27
+ data: { data: [] },
28
+ error: null,
29
+ }));
30
+
31
+ vi.mock('resend', () => ({
32
+ Resend: class MockResend {
33
+ constructor(public key: string) {}
34
+ emails = { send: mockSend };
35
+ domains = { list: mockDomainsList };
36
+ },
37
+ }));
38
+
39
+ describe('send command', () => {
40
+ const restoreEnv = captureTestEnv();
41
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
42
+ let errorSpy: MockInstance | undefined;
43
+ let stderrSpy: MockInstance | undefined;
44
+ let exitSpy: MockInstance | undefined;
45
+
46
+ beforeEach(() => {
47
+ process.env.RESEND_API_KEY = 're_test_key';
48
+ mockSend.mockClear();
49
+ mockDomainsList.mockClear();
50
+ });
51
+
52
+ afterEach(() => {
53
+ restoreEnv();
54
+ errorSpy?.mockRestore();
55
+ stderrSpy?.mockRestore();
56
+ exitSpy?.mockRestore();
57
+ spies = undefined;
58
+ errorSpy = undefined;
59
+ stderrSpy = undefined;
60
+ exitSpy = undefined;
61
+ });
62
+
63
+ test('sends email with all flags provided', async () => {
64
+ spies = setupOutputSpies();
65
+
66
+ const { sendCommand } = await import('../../../src/commands/emails/send');
67
+ await sendCommand.parseAsync(
68
+ [
69
+ '--from',
70
+ 'a@test.com',
71
+ '--to',
72
+ 'b@test.com',
73
+ '--subject',
74
+ 'Test',
75
+ '--text',
76
+ 'Hello',
77
+ ],
78
+ { from: 'user' },
79
+ );
80
+
81
+ expect(mockSend).toHaveBeenCalledTimes(1);
82
+ const callArgs = mockSend.mock.calls[0][0] as Record<string, unknown>;
83
+ expect(callArgs.from).toBe('a@test.com');
84
+ expect(callArgs.to).toEqual(['b@test.com']);
85
+ expect(callArgs.subject).toBe('Test');
86
+ expect(callArgs.text).toBe('Hello');
87
+ });
88
+
89
+ test('outputs JSON with email ID on success', async () => {
90
+ spies = setupOutputSpies();
91
+
92
+ const { sendCommand } = await import('../../../src/commands/emails/send');
93
+ await sendCommand.parseAsync(
94
+ [
95
+ '--from',
96
+ 'a@test.com',
97
+ '--to',
98
+ 'b@test.com',
99
+ '--subject',
100
+ 'Test',
101
+ '--text',
102
+ 'Body',
103
+ ],
104
+ { from: 'user' },
105
+ );
106
+
107
+ const output = spies.logSpy.mock.calls[0][0] as string;
108
+ const parsed = JSON.parse(output);
109
+ expect(parsed.id).toBe('test-email-id-123');
110
+ });
111
+
112
+ test('sends HTML email when --html provided', async () => {
113
+ spies = setupOutputSpies();
114
+
115
+ const { sendCommand } = await import('../../../src/commands/emails/send');
116
+ await sendCommand.parseAsync(
117
+ [
118
+ '--from',
119
+ 'a@test.com',
120
+ '--to',
121
+ 'b@test.com',
122
+ '--subject',
123
+ 'Test',
124
+ '--html',
125
+ '<h1>Hello</h1>',
126
+ ],
127
+ { from: 'user' },
128
+ );
129
+
130
+ const callArgs = mockSend.mock.calls[0][0] as Record<string, unknown>;
131
+ expect(callArgs.html).toBe('<h1>Hello</h1>');
132
+ expect(callArgs.text).toBeUndefined();
133
+ });
134
+
135
+ test('supports multiple --to addresses', async () => {
136
+ spies = setupOutputSpies();
137
+
138
+ const { sendCommand } = await import('../../../src/commands/emails/send');
139
+ await sendCommand.parseAsync(
140
+ [
141
+ '--from',
142
+ 'a@test.com',
143
+ '--to',
144
+ 'b@test.com',
145
+ 'c@test.com',
146
+ '--subject',
147
+ 'Test',
148
+ '--text',
149
+ 'Hi',
150
+ ],
151
+ { from: 'user' },
152
+ );
153
+
154
+ const callArgs = mockSend.mock.calls[0][0] as Record<string, unknown>;
155
+ expect(callArgs.to).toEqual(['b@test.com', 'c@test.com']);
156
+ });
157
+
158
+ test('errors when no API key and non-interactive', async () => {
159
+ setNonInteractive();
160
+ delete process.env.RESEND_API_KEY;
161
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
162
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
163
+ exitSpy = mockExitThrow();
164
+
165
+ const { sendCommand } = await import('../../../src/commands/emails/send');
166
+ await expectExit1(() =>
167
+ sendCommand.parseAsync(
168
+ [
169
+ '--from',
170
+ 'a@test.com',
171
+ '--to',
172
+ 'b@test.com',
173
+ '--subject',
174
+ 'Test',
175
+ '--text',
176
+ 'Hi',
177
+ ],
178
+ { from: 'user' },
179
+ ),
180
+ );
181
+ });
182
+
183
+ test('errors listing missing flags in non-interactive mode', async () => {
184
+ setNonInteractive();
185
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
186
+ exitSpy = mockExitThrow();
187
+
188
+ const { sendCommand } = await import('../../../src/commands/emails/send');
189
+ await expectExit1(() =>
190
+ sendCommand.parseAsync(['--from', 'a@test.com'], { from: 'user' }),
191
+ );
192
+
193
+ const allErrors = errorSpy.mock.calls.map((c) => c[0]).join(' ');
194
+ expect(allErrors).toContain('--to');
195
+ expect(allErrors).toContain('--subject');
196
+ });
197
+
198
+ test('errors when no body and non-interactive', async () => {
199
+ setNonInteractive();
200
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
201
+ exitSpy = mockExitThrow();
202
+
203
+ const { sendCommand } = await import('../../../src/commands/emails/send');
204
+ await expectExit1(() =>
205
+ sendCommand.parseAsync(
206
+ ['--from', 'a@test.com', '--to', 'b@test.com', '--subject', 'Test'],
207
+ { from: 'user' },
208
+ ),
209
+ );
210
+ });
211
+
212
+ test('reads HTML body from --html-file', async () => {
213
+ spies = setupOutputSpies();
214
+
215
+ const tmpFile = join(
216
+ dirname(fileURLToPath(import.meta.url)),
217
+ '__test_email.html',
218
+ );
219
+ writeFileSync(tmpFile, '<h1>From file</h1>');
220
+
221
+ try {
222
+ const { sendCommand } = await import('../../../src/commands/emails/send');
223
+ await sendCommand.parseAsync(
224
+ [
225
+ '--from',
226
+ 'a@test.com',
227
+ '--to',
228
+ 'b@test.com',
229
+ '--subject',
230
+ 'Test',
231
+ '--html-file',
232
+ tmpFile,
233
+ ],
234
+ { from: 'user' },
235
+ );
236
+
237
+ const callArgs = mockSend.mock.calls[0][0] as Record<string, unknown>;
238
+ expect(callArgs.html).toBe('<h1>From file</h1>');
239
+ } finally {
240
+ unlinkSync(tmpFile);
241
+ }
242
+ });
243
+
244
+ test('passes cc, bcc, reply-to when provided', async () => {
245
+ spies = setupOutputSpies();
246
+
247
+ const { sendCommand } = await import('../../../src/commands/emails/send');
248
+ await sendCommand.parseAsync(
249
+ [
250
+ '--from',
251
+ 'a@test.com',
252
+ '--to',
253
+ 'b@test.com',
254
+ '--subject',
255
+ 'Test',
256
+ '--text',
257
+ 'Body',
258
+ '--cc',
259
+ 'cc@test.com',
260
+ '--bcc',
261
+ 'bcc@test.com',
262
+ '--reply-to',
263
+ 'reply@test.com',
264
+ ],
265
+ { from: 'user' },
266
+ );
267
+
268
+ const callArgs = mockSend.mock.calls[0][0] as Record<string, unknown>;
269
+ expect(callArgs.cc).toEqual(['cc@test.com']);
270
+ expect(callArgs.bcc).toEqual(['bcc@test.com']);
271
+ expect(callArgs.replyTo).toBe('reply@test.com');
272
+ });
273
+
274
+ test('does not call domains.list when --from is provided', async () => {
275
+ spies = setupOutputSpies();
276
+
277
+ const { sendCommand } = await import('../../../src/commands/emails/send');
278
+ await sendCommand.parseAsync(
279
+ [
280
+ '--from',
281
+ 'a@test.com',
282
+ '--to',
283
+ 'b@test.com',
284
+ '--subject',
285
+ 'Test',
286
+ '--text',
287
+ 'Hello',
288
+ ],
289
+ { from: 'user' },
290
+ );
291
+
292
+ expect(mockDomainsList).not.toHaveBeenCalled();
293
+ expect(mockSend).toHaveBeenCalledTimes(1);
294
+ });
295
+
296
+ test('degrades gracefully when domain fetch fails', async () => {
297
+ const { fetchVerifiedDomains } = await import(
298
+ '../../../src/commands/emails/send'
299
+ );
300
+ const failingResend = {
301
+ domains: {
302
+ list: vi.fn(async () => {
303
+ throw new Error('Network error');
304
+ }),
305
+ },
306
+ } as Record<string, unknown>;
307
+
308
+ // Should return [] without throwing, so the caller falls through to promptForMissing
309
+ const result = await fetchVerifiedDomains(failingResend);
310
+ expect(result).toEqual([]);
311
+ });
312
+ });
@@ -0,0 +1,164 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ type MockInstance,
7
+ test,
8
+ vi,
9
+ } from 'vitest';
10
+ import {
11
+ captureTestEnv,
12
+ expectExit1,
13
+ mockExitThrow,
14
+ mockSdkError,
15
+ setNonInteractive,
16
+ setupOutputSpies,
17
+ } from '../../helpers';
18
+
19
+ const mockCreate = vi.fn(async () => ({
20
+ data: {
21
+ object: 'segment' as const,
22
+ id: '3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c',
23
+ name: 'Newsletter Subscribers',
24
+ },
25
+ error: null,
26
+ }));
27
+
28
+ vi.mock('resend', () => ({
29
+ Resend: class MockResend {
30
+ constructor(public key: string) {}
31
+ segments = { create: mockCreate };
32
+ },
33
+ }));
34
+
35
+ describe('segments create command', () => {
36
+ const restoreEnv = captureTestEnv();
37
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
38
+ let errorSpy: MockInstance | undefined;
39
+ let stderrSpy: MockInstance | undefined;
40
+ let exitSpy: MockInstance | undefined;
41
+
42
+ beforeEach(() => {
43
+ process.env.RESEND_API_KEY = 're_test_key';
44
+ mockCreate.mockClear();
45
+ });
46
+
47
+ afterEach(() => {
48
+ restoreEnv();
49
+ errorSpy?.mockRestore();
50
+ stderrSpy?.mockRestore();
51
+ exitSpy?.mockRestore();
52
+ spies = undefined;
53
+ errorSpy = undefined;
54
+ stderrSpy = undefined;
55
+ exitSpy = undefined;
56
+ });
57
+
58
+ test('creates segment with --name flag', async () => {
59
+ spies = setupOutputSpies();
60
+
61
+ const { createSegmentCommand } = await import(
62
+ '../../../src/commands/segments/create'
63
+ );
64
+ await createSegmentCommand.parseAsync(
65
+ ['--name', 'Newsletter Subscribers'],
66
+ { from: 'user' },
67
+ );
68
+
69
+ expect(mockCreate).toHaveBeenCalledTimes(1);
70
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
71
+ expect(args.name).toBe('Newsletter Subscribers');
72
+ });
73
+
74
+ test('outputs JSON with id and object when non-interactive', async () => {
75
+ spies = setupOutputSpies();
76
+
77
+ const { createSegmentCommand } = await import(
78
+ '../../../src/commands/segments/create'
79
+ );
80
+ await createSegmentCommand.parseAsync(
81
+ ['--name', 'Newsletter Subscribers'],
82
+ { from: 'user' },
83
+ );
84
+
85
+ const output = spies.logSpy.mock.calls[0][0] as string;
86
+ const parsed = JSON.parse(output);
87
+ expect(parsed.object).toBe('segment');
88
+ expect(parsed.id).toBe('3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c');
89
+ expect(parsed.name).toBe('Newsletter Subscribers');
90
+ });
91
+
92
+ test('errors with missing_name in non-interactive mode when --name absent', async () => {
93
+ setNonInteractive();
94
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
95
+ exitSpy = mockExitThrow();
96
+
97
+ const { createSegmentCommand } = await import(
98
+ '../../../src/commands/segments/create'
99
+ );
100
+ await expectExit1(() =>
101
+ createSegmentCommand.parseAsync([], { from: 'user' }),
102
+ );
103
+
104
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
105
+ expect(output).toContain('missing_name');
106
+ });
107
+
108
+ test('does not call SDK when missing_name error is raised', async () => {
109
+ setNonInteractive();
110
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
111
+ exitSpy = mockExitThrow();
112
+
113
+ const { createSegmentCommand } = await import(
114
+ '../../../src/commands/segments/create'
115
+ );
116
+ await expectExit1(() =>
117
+ createSegmentCommand.parseAsync([], { from: 'user' }),
118
+ );
119
+
120
+ expect(mockCreate).not.toHaveBeenCalled();
121
+ });
122
+
123
+ test('errors with auth_error when no API key', async () => {
124
+ setNonInteractive();
125
+ delete process.env.RESEND_API_KEY;
126
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
127
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
128
+ exitSpy = mockExitThrow();
129
+
130
+ const { createSegmentCommand } = await import(
131
+ '../../../src/commands/segments/create'
132
+ );
133
+ await expectExit1(() =>
134
+ createSegmentCommand.parseAsync(['--name', 'Test'], { from: 'user' }),
135
+ );
136
+
137
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
138
+ expect(output).toContain('auth_error');
139
+ });
140
+
141
+ test('errors with create_error when SDK returns an error', async () => {
142
+ setNonInteractive();
143
+ mockCreate.mockResolvedValueOnce(
144
+ mockSdkError('Segment already exists', 'validation_error'),
145
+ );
146
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
147
+ stderrSpy = vi
148
+ .spyOn(process.stderr, 'write')
149
+ .mockImplementation(() => true);
150
+ exitSpy = mockExitThrow();
151
+
152
+ const { createSegmentCommand } = await import(
153
+ '../../../src/commands/segments/create'
154
+ );
155
+ await expectExit1(() =>
156
+ createSegmentCommand.parseAsync(['--name', 'Newsletter Subscribers'], {
157
+ from: 'user',
158
+ }),
159
+ );
160
+
161
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
162
+ expect(output).toContain('create_error');
163
+ });
164
+ });
@@ -0,0 +1,183 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ type MockInstance,
7
+ test,
8
+ vi,
9
+ } from 'vitest';
10
+ import {
11
+ captureTestEnv,
12
+ expectExit1,
13
+ mockExitThrow,
14
+ mockSdkError,
15
+ setNonInteractive,
16
+ setupOutputSpies,
17
+ } from '../../helpers';
18
+
19
+ const mockRemove = vi.fn(async () => ({
20
+ data: {
21
+ object: 'segment' as const,
22
+ id: '3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c',
23
+ deleted: true,
24
+ },
25
+ error: null,
26
+ }));
27
+
28
+ vi.mock('resend', () => ({
29
+ Resend: class MockResend {
30
+ constructor(public key: string) {}
31
+ segments = { remove: mockRemove };
32
+ },
33
+ }));
34
+
35
+ describe('segments delete command', () => {
36
+ const restoreEnv = captureTestEnv();
37
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
38
+ let errorSpy: MockInstance | undefined;
39
+ let stderrSpy: MockInstance | undefined;
40
+ let exitSpy: MockInstance | undefined;
41
+
42
+ beforeEach(() => {
43
+ process.env.RESEND_API_KEY = 're_test_key';
44
+ mockRemove.mockClear();
45
+ });
46
+
47
+ afterEach(() => {
48
+ restoreEnv();
49
+ errorSpy?.mockRestore();
50
+ stderrSpy?.mockRestore();
51
+ exitSpy?.mockRestore();
52
+ spies = undefined;
53
+ errorSpy = undefined;
54
+ stderrSpy = undefined;
55
+ exitSpy = undefined;
56
+ });
57
+
58
+ test('deletes segment with --yes flag', async () => {
59
+ spies = setupOutputSpies();
60
+
61
+ const { deleteSegmentCommand } = await import(
62
+ '../../../src/commands/segments/delete'
63
+ );
64
+ await deleteSegmentCommand.parseAsync(
65
+ ['3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c', '--yes'],
66
+ {
67
+ from: 'user',
68
+ },
69
+ );
70
+
71
+ expect(mockRemove).toHaveBeenCalledTimes(1);
72
+ expect(mockRemove.mock.calls[0][0]).toBe(
73
+ '3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c',
74
+ );
75
+ });
76
+
77
+ test('outputs synthesized JSON result when non-interactive', async () => {
78
+ spies = setupOutputSpies();
79
+
80
+ const { deleteSegmentCommand } = await import(
81
+ '../../../src/commands/segments/delete'
82
+ );
83
+ await deleteSegmentCommand.parseAsync(
84
+ ['3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c', '--yes'],
85
+ {
86
+ from: 'user',
87
+ },
88
+ );
89
+
90
+ const output = spies.logSpy.mock.calls[0][0] as string;
91
+ const parsed = JSON.parse(output);
92
+ expect(parsed.object).toBe('segment');
93
+ expect(parsed.id).toBe('3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c');
94
+ expect(parsed.deleted).toBe(true);
95
+ });
96
+
97
+ test('errors with confirmation_required when --yes absent in non-interactive mode', async () => {
98
+ setNonInteractive();
99
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
100
+ exitSpy = mockExitThrow();
101
+
102
+ const { deleteSegmentCommand } = await import(
103
+ '../../../src/commands/segments/delete'
104
+ );
105
+ await expectExit1(() =>
106
+ deleteSegmentCommand.parseAsync(
107
+ ['3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c'],
108
+ { from: 'user' },
109
+ ),
110
+ );
111
+
112
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
113
+ expect(output).toContain('confirmation_required');
114
+ });
115
+
116
+ test('does not call SDK when confirmation_required error is raised', async () => {
117
+ setNonInteractive();
118
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
119
+ exitSpy = mockExitThrow();
120
+
121
+ const { deleteSegmentCommand } = await import(
122
+ '../../../src/commands/segments/delete'
123
+ );
124
+ await expectExit1(() =>
125
+ deleteSegmentCommand.parseAsync(
126
+ ['3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c'],
127
+ { from: 'user' },
128
+ ),
129
+ );
130
+
131
+ expect(mockRemove).not.toHaveBeenCalled();
132
+ });
133
+
134
+ test('errors with auth_error when no API key', async () => {
135
+ setNonInteractive();
136
+ delete process.env.RESEND_API_KEY;
137
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
138
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
139
+ exitSpy = mockExitThrow();
140
+
141
+ const { deleteSegmentCommand } = await import(
142
+ '../../../src/commands/segments/delete'
143
+ );
144
+ await expectExit1(() =>
145
+ deleteSegmentCommand.parseAsync(
146
+ ['3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c', '--yes'],
147
+ {
148
+ from: 'user',
149
+ },
150
+ ),
151
+ );
152
+
153
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
154
+ expect(output).toContain('auth_error');
155
+ });
156
+
157
+ test('errors with delete_error when SDK returns an error', async () => {
158
+ setNonInteractive();
159
+ mockRemove.mockResolvedValueOnce(
160
+ mockSdkError('Segment not found', 'not_found'),
161
+ );
162
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
163
+ stderrSpy = vi
164
+ .spyOn(process.stderr, 'write')
165
+ .mockImplementation(() => true);
166
+ exitSpy = mockExitThrow();
167
+
168
+ const { deleteSegmentCommand } = await import(
169
+ '../../../src/commands/segments/delete'
170
+ );
171
+ await expectExit1(() =>
172
+ deleteSegmentCommand.parseAsync(
173
+ ['00000000-0000-0000-0000-000000000000', '--yes'],
174
+ {
175
+ from: 'user',
176
+ },
177
+ ),
178
+ );
179
+
180
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
181
+ expect(output).toContain('delete_error');
182
+ });
183
+ });