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,118 @@
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 mockVerify = vi.fn(async () => ({
20
+ data: { object: 'domain', id: 'test-domain-id' },
21
+ error: null,
22
+ }));
23
+
24
+ vi.mock('resend', () => ({
25
+ Resend: class MockResend {
26
+ constructor(public key: string) {}
27
+ domains = { verify: mockVerify };
28
+ },
29
+ }));
30
+
31
+ describe('domains verify command', () => {
32
+ const restoreEnv = captureTestEnv();
33
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
34
+ let errorSpy: MockInstance | undefined;
35
+ let stderrSpy: MockInstance | undefined;
36
+ let exitSpy: MockInstance | undefined;
37
+
38
+ beforeEach(() => {
39
+ process.env.RESEND_API_KEY = 're_test_key';
40
+ mockVerify.mockClear();
41
+ });
42
+
43
+ afterEach(() => {
44
+ restoreEnv();
45
+ errorSpy?.mockRestore();
46
+ stderrSpy?.mockRestore();
47
+ exitSpy?.mockRestore();
48
+ spies = undefined;
49
+ errorSpy = undefined;
50
+ stderrSpy = undefined;
51
+ exitSpy = undefined;
52
+ });
53
+
54
+ test('calls SDK verify with correct id', async () => {
55
+ spies = setupOutputSpies();
56
+
57
+ const { verifyDomainCommand } = await import(
58
+ '../../../src/commands/domains/verify'
59
+ );
60
+ await verifyDomainCommand.parseAsync(['test-domain-id'], { from: 'user' });
61
+
62
+ expect(mockVerify).toHaveBeenCalledWith('test-domain-id');
63
+ });
64
+
65
+ test('outputs JSON object in non-interactive mode (stdout not a TTY)', async () => {
66
+ spies = setupOutputSpies();
67
+
68
+ const { verifyDomainCommand } = await import(
69
+ '../../../src/commands/domains/verify'
70
+ );
71
+ await verifyDomainCommand.parseAsync(['test-domain-id'], { from: 'user' });
72
+
73
+ const output = spies.logSpy.mock.calls[0][0] as string;
74
+ const parsed = JSON.parse(output);
75
+ expect(parsed.id).toBe('test-domain-id');
76
+ expect(parsed.object).toBe('domain');
77
+ });
78
+
79
+ test('errors with auth_error when no API key', async () => {
80
+ setNonInteractive();
81
+ delete process.env.RESEND_API_KEY;
82
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
83
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
84
+ exitSpy = mockExitThrow();
85
+
86
+ const { verifyDomainCommand } = await import(
87
+ '../../../src/commands/domains/verify'
88
+ );
89
+ await expectExit1(() =>
90
+ verifyDomainCommand.parseAsync(['test-domain-id'], { from: 'user' }),
91
+ );
92
+
93
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
94
+ expect(output).toContain('auth_error');
95
+ });
96
+
97
+ test('errors with verify_error when SDK returns an error', async () => {
98
+ setNonInteractive();
99
+ mockVerify.mockResolvedValueOnce(
100
+ mockSdkError('Domain not found', 'not_found'),
101
+ );
102
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
103
+ stderrSpy = vi
104
+ .spyOn(process.stderr, 'write')
105
+ .mockImplementation(() => true);
106
+ exitSpy = mockExitThrow();
107
+
108
+ const { verifyDomainCommand } = await import(
109
+ '../../../src/commands/domains/verify'
110
+ );
111
+ await expectExit1(() =>
112
+ verifyDomainCommand.parseAsync(['test-domain-id'], { from: 'user' }),
113
+ );
114
+
115
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
116
+ expect(output).toContain('verify_error');
117
+ });
118
+ });
@@ -0,0 +1,324 @@
1
+ import { 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 mockBatchSend = vi.fn(async () => ({
22
+ data: { data: [{ id: 'abc123' }, { id: 'def456' }] },
23
+ error: null,
24
+ }));
25
+
26
+ vi.mock('resend', () => ({
27
+ Resend: class MockResend {
28
+ constructor(public key: string) {}
29
+ batch = { send: mockBatchSend };
30
+ },
31
+ }));
32
+
33
+ const VALID_EMAILS = [
34
+ {
35
+ from: 'you@domain.com',
36
+ to: ['user1@example.com'],
37
+ subject: 'Hello 1',
38
+ html: '<p>Hello 1</p>',
39
+ },
40
+ {
41
+ from: 'you@domain.com',
42
+ to: ['user2@example.com'],
43
+ subject: 'Hello 2',
44
+ text: 'Hello 2',
45
+ },
46
+ ];
47
+
48
+ describe('batch command', () => {
49
+ const restoreEnv = captureTestEnv();
50
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
51
+ let errorSpy: MockInstance | undefined;
52
+ let stderrSpy: MockInstance | undefined;
53
+ let exitSpy: MockInstance | undefined;
54
+ let tmpFile: string;
55
+
56
+ beforeEach(() => {
57
+ process.env.RESEND_API_KEY = 're_test_key';
58
+ mockBatchSend.mockClear();
59
+ });
60
+
61
+ afterEach(async () => {
62
+ restoreEnv();
63
+ errorSpy?.mockRestore();
64
+ stderrSpy?.mockRestore();
65
+ exitSpy?.mockRestore();
66
+ spies = undefined;
67
+ errorSpy = undefined;
68
+ stderrSpy = undefined;
69
+ exitSpy = undefined;
70
+ if (tmpFile) {
71
+ const { unlinkSync } = require('node:fs');
72
+ try {
73
+ unlinkSync(tmpFile);
74
+ } catch {}
75
+ tmpFile = '';
76
+ }
77
+ });
78
+
79
+ async function writeTmpJson(content: unknown): Promise<string> {
80
+ const path = join(
81
+ dirname(fileURLToPath(import.meta.url)),
82
+ '__test_batch.json',
83
+ );
84
+ writeFileSync(path, JSON.stringify(content));
85
+ tmpFile = path;
86
+ return path;
87
+ }
88
+
89
+ test('sends emails from a JSON file', async () => {
90
+ spies = setupOutputSpies();
91
+
92
+ const file = await writeTmpJson(VALID_EMAILS);
93
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
94
+ await batchCommand.parseAsync(['--file', file], { from: 'user' });
95
+
96
+ expect(mockBatchSend).toHaveBeenCalledTimes(1);
97
+ const emails = mockBatchSend.mock.calls[0][0] as unknown[];
98
+ expect(emails).toHaveLength(2);
99
+ });
100
+
101
+ test('outputs array of IDs on success in JSON mode', async () => {
102
+ // Non-interactive mode (no TTY) automatically triggers JSON output via outputResult
103
+ spies = setupOutputSpies();
104
+
105
+ const file = await writeTmpJson(VALID_EMAILS);
106
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
107
+ await batchCommand.parseAsync(['--file', file], { from: 'user' });
108
+
109
+ const output = spies.logSpy.mock.calls[0][0] as string;
110
+ const parsed = JSON.parse(output);
111
+ expect(parsed).toEqual([{ id: 'abc123' }, { id: 'def456' }]);
112
+ });
113
+
114
+ test('errors with missing_file when no --file in non-interactive mode', async () => {
115
+ setNonInteractive();
116
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
117
+ exitSpy = mockExitThrow();
118
+
119
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
120
+ await expectExit1(() => batchCommand.parseAsync([], { from: 'user' }));
121
+
122
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
123
+ expect(output).toContain('missing_file');
124
+ });
125
+
126
+ test('errors with file_read_error when file does not exist', async () => {
127
+ setNonInteractive();
128
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
129
+ exitSpy = mockExitThrow();
130
+
131
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
132
+ await expectExit1(() =>
133
+ batchCommand.parseAsync(
134
+ ['--file', '/tmp/nonexistent-resend-batch.json'],
135
+ { from: 'user' },
136
+ ),
137
+ );
138
+
139
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
140
+ expect(output).toContain('file_read_error');
141
+ });
142
+
143
+ test('errors with invalid_json when file is not valid JSON', async () => {
144
+ setNonInteractive();
145
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
146
+ exitSpy = mockExitThrow();
147
+
148
+ const path = join(
149
+ dirname(fileURLToPath(import.meta.url)),
150
+ '__test_batch_bad.json',
151
+ );
152
+ writeFileSync(path, 'not valid json{{{');
153
+ tmpFile = path;
154
+
155
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
156
+ await expectExit1(() =>
157
+ batchCommand.parseAsync(['--file', path], { from: 'user' }),
158
+ );
159
+
160
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
161
+ expect(output).toContain('invalid_json');
162
+ });
163
+
164
+ test('errors with invalid_format when file content is not an array', async () => {
165
+ setNonInteractive();
166
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
167
+ exitSpy = mockExitThrow();
168
+
169
+ const file = await writeTmpJson({
170
+ from: 'you@domain.com',
171
+ to: ['user@example.com'],
172
+ });
173
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
174
+ await expectExit1(() =>
175
+ batchCommand.parseAsync(['--file', file], { from: 'user' }),
176
+ );
177
+
178
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
179
+ expect(output).toContain('invalid_format');
180
+ // Regression: invalid_format check was inside the try block; ExitError thrown by
181
+ // outputError (when process.exit is mocked) would be caught, firing invalid_json too.
182
+ expect(output).not.toContain('invalid_json');
183
+ });
184
+
185
+ test('rejects entries with attachments', async () => {
186
+ setNonInteractive();
187
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
188
+ exitSpy = mockExitThrow();
189
+
190
+ const emails = [
191
+ {
192
+ ...VALID_EMAILS[0],
193
+ attachments: [{ filename: 'test.txt', content: 'hello' }],
194
+ },
195
+ ];
196
+ const file = await writeTmpJson(emails);
197
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
198
+ await expectExit1(() =>
199
+ batchCommand.parseAsync(['--file', file], { from: 'user' }),
200
+ );
201
+
202
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
203
+ expect(output).toContain('attachments');
204
+ });
205
+
206
+ test('rejects entries with scheduled_at', async () => {
207
+ setNonInteractive();
208
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
209
+ exitSpy = mockExitThrow();
210
+
211
+ const emails = [
212
+ { ...VALID_EMAILS[0], scheduled_at: '2026-01-01T00:00:00Z' },
213
+ ];
214
+ const file = await writeTmpJson(emails);
215
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
216
+ await expectExit1(() =>
217
+ batchCommand.parseAsync(['--file', file], { from: 'user' }),
218
+ );
219
+
220
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
221
+ expect(output).toContain('scheduled_at');
222
+ });
223
+
224
+ test('warns but continues when array length exceeds 100', async () => {
225
+ spies = setupOutputSpies();
226
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
227
+
228
+ const emails = Array.from({ length: 101 }, (_, i) => ({
229
+ from: 'you@domain.com',
230
+ to: [`user${i}@example.com`],
231
+ subject: `Hello ${i}`,
232
+ text: `Hello ${i}`,
233
+ }));
234
+ const file = await writeTmpJson(emails);
235
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
236
+ await batchCommand.parseAsync(['--file', file], { from: 'user' });
237
+
238
+ expect(mockBatchSend).toHaveBeenCalledTimes(1);
239
+
240
+ warnSpy.mockRestore();
241
+ });
242
+
243
+ test('passes idempotency key to batch.send', async () => {
244
+ spies = setupOutputSpies();
245
+
246
+ const file = await writeTmpJson(VALID_EMAILS);
247
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
248
+ await batchCommand.parseAsync(
249
+ ['--file', file, '--idempotency-key', 'my-key-123'],
250
+ { from: 'user' },
251
+ );
252
+
253
+ expect(mockBatchSend).toHaveBeenCalledTimes(1);
254
+ const opts = mockBatchSend.mock.calls[0][1] as Record<string, unknown>;
255
+ expect(opts?.idempotencyKey).toBe('my-key-123');
256
+ });
257
+
258
+ test('errors with auth_error when no API key in non-interactive mode', async () => {
259
+ setNonInteractive();
260
+ delete process.env.RESEND_API_KEY;
261
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
262
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
263
+ exitSpy = mockExitThrow();
264
+
265
+ const file = await writeTmpJson(VALID_EMAILS);
266
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
267
+ await expectExit1(() =>
268
+ batchCommand.parseAsync(['--file', file], { from: 'user' }),
269
+ );
270
+
271
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
272
+ expect(output).toContain('auth_error');
273
+ });
274
+
275
+ test('outputs human-readable summary in terminal mode', async () => {
276
+ // Make it look like a TTY so outputResult uses human-readable format
277
+ Object.defineProperty(process.stdin, 'isTTY', {
278
+ value: true,
279
+ writable: true,
280
+ });
281
+ Object.defineProperty(process.stdout, 'isTTY', {
282
+ value: true,
283
+ writable: true,
284
+ });
285
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
286
+ stderrSpy = vi
287
+ .spyOn(process.stderr, 'write')
288
+ .mockImplementation(() => true);
289
+
290
+ const file = await writeTmpJson(VALID_EMAILS);
291
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
292
+ await batchCommand.parseAsync(['--file', file], { from: 'user' });
293
+
294
+ const allOutput = logSpy.mock.calls.map((c) => c[0]).join('\n');
295
+ expect(allOutput).toContain('2');
296
+ expect(allOutput).toContain('abc123');
297
+ expect(allOutput).toContain('def456');
298
+
299
+ logSpy.mockRestore();
300
+ });
301
+
302
+ test('errors with batch_error when SDK returns an error', async () => {
303
+ setNonInteractive();
304
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
305
+ stderrSpy = vi
306
+ .spyOn(process.stderr, 'write')
307
+ .mockImplementation(() => true);
308
+ exitSpy = mockExitThrow();
309
+
310
+ mockBatchSend.mockImplementationOnce(async () => ({
311
+ data: null,
312
+ error: { message: 'Rate limit exceeded', name: 'rate_limit_exceeded' },
313
+ }));
314
+
315
+ const file = await writeTmpJson(VALID_EMAILS);
316
+ const { batchCommand } = await import('../../../src/commands/emails/batch');
317
+ await expectExit1(() =>
318
+ batchCommand.parseAsync(['--file', file], { from: 'user' }),
319
+ );
320
+
321
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
322
+ expect(output).toContain('batch_error');
323
+ });
324
+ });
@@ -0,0 +1,132 @@
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 mockGet = vi.fn(async () => ({
20
+ data: {
21
+ object: 'email' as const,
22
+ id: 'email_abc123',
23
+ from: 'you@domain.com',
24
+ to: ['user@example.com'],
25
+ subject: 'Hello',
26
+ html: '<p>Hi</p>',
27
+ text: 'Hi',
28
+ created_at: '2026-02-18T12:00:00.000Z',
29
+ scheduled_at: null,
30
+ last_event: 'delivered' as const,
31
+ bcc: null,
32
+ cc: null,
33
+ reply_to: null,
34
+ },
35
+ error: null,
36
+ }));
37
+
38
+ vi.mock('resend', () => ({
39
+ Resend: class MockResend {
40
+ constructor(public key: string) {}
41
+ emails = { get: mockGet };
42
+ },
43
+ }));
44
+
45
+ describe('emails get command', () => {
46
+ const restoreEnv = captureTestEnv();
47
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
48
+ let errorSpy: MockInstance | undefined;
49
+ let stderrSpy: MockInstance | undefined;
50
+ let exitSpy: MockInstance | undefined;
51
+
52
+ beforeEach(() => {
53
+ process.env.RESEND_API_KEY = 're_test_key';
54
+ mockGet.mockClear();
55
+ });
56
+
57
+ afterEach(() => {
58
+ restoreEnv();
59
+ errorSpy?.mockRestore();
60
+ stderrSpy?.mockRestore();
61
+ exitSpy?.mockRestore();
62
+ spies = undefined;
63
+ errorSpy = undefined;
64
+ stderrSpy = undefined;
65
+ exitSpy = undefined;
66
+ });
67
+
68
+ test('calls SDK get with the provided id', async () => {
69
+ spies = setupOutputSpies();
70
+
71
+ const { getEmailCommand } = await import(
72
+ '../../../src/commands/emails/get'
73
+ );
74
+ await getEmailCommand.parseAsync(['email_abc123'], { from: 'user' });
75
+
76
+ expect(mockGet).toHaveBeenCalledWith('email_abc123');
77
+ });
78
+
79
+ test('outputs JSON with full email fields when non-interactive', async () => {
80
+ spies = setupOutputSpies();
81
+
82
+ const { getEmailCommand } = await import(
83
+ '../../../src/commands/emails/get'
84
+ );
85
+ await getEmailCommand.parseAsync(['email_abc123'], { from: 'user' });
86
+
87
+ const output = spies.logSpy.mock.calls[0][0] as string;
88
+ const parsed = JSON.parse(output);
89
+ expect(parsed.id).toBe('email_abc123');
90
+ expect(parsed.from).toBe('you@domain.com');
91
+ expect(parsed.subject).toBe('Hello');
92
+ expect(parsed.last_event).toBe('delivered');
93
+ });
94
+
95
+ test('errors with auth_error when no API key', async () => {
96
+ setNonInteractive();
97
+ delete process.env.RESEND_API_KEY;
98
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
99
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
100
+ exitSpy = mockExitThrow();
101
+
102
+ const { getEmailCommand } = await import(
103
+ '../../../src/commands/emails/get'
104
+ );
105
+ await expectExit1(() =>
106
+ getEmailCommand.parseAsync(['email_abc123'], { from: 'user' }),
107
+ );
108
+
109
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
110
+ expect(output).toContain('auth_error');
111
+ });
112
+
113
+ test('errors with fetch_error when SDK returns an error', async () => {
114
+ setNonInteractive();
115
+ mockGet.mockResolvedValueOnce(mockSdkError('Not found', 'not_found'));
116
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
117
+ stderrSpy = vi
118
+ .spyOn(process.stderr, 'write')
119
+ .mockImplementation(() => true);
120
+ exitSpy = mockExitThrow();
121
+
122
+ const { getEmailCommand } = await import(
123
+ '../../../src/commands/emails/get'
124
+ );
125
+ await expectExit1(() =>
126
+ getEmailCommand.parseAsync(['email_nonexistent'], { from: 'user' }),
127
+ );
128
+
129
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
130
+ expect(output).toContain('fetch_error');
131
+ });
132
+ });