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,136 @@
1
+ import {
2
+ afterEach,
3
+ describe,
4
+ expect,
5
+ type MockInstance,
6
+ test,
7
+ vi,
8
+ } from 'vitest';
9
+ import { outputError, outputResult } from '../../src/lib/output';
10
+
11
+ describe('outputResult', () => {
12
+ let logSpy: MockInstance;
13
+ const originalIsTTY = process.stdout.isTTY;
14
+
15
+ afterEach(() => {
16
+ logSpy?.mockRestore();
17
+ Object.defineProperty(process.stdout, 'isTTY', {
18
+ value: originalIsTTY,
19
+ writable: true,
20
+ });
21
+ });
22
+
23
+ test('outputs JSON when json option is true', () => {
24
+ logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
25
+ outputResult({ id: '123' }, { json: true });
26
+ expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
27
+ });
28
+
29
+ test('outputs JSON when stdout is not TTY', () => {
30
+ Object.defineProperty(process.stdout, 'isTTY', {
31
+ value: undefined,
32
+ writable: true,
33
+ });
34
+ logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
35
+ outputResult({ id: '123' });
36
+ expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
37
+ });
38
+
39
+ test('outputs string directly for human-readable mode', () => {
40
+ Object.defineProperty(process.stdout, 'isTTY', {
41
+ value: true,
42
+ writable: true,
43
+ });
44
+ logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
45
+ outputResult('Email sent successfully');
46
+ expect(logSpy).toHaveBeenCalledWith('Email sent successfully');
47
+ });
48
+
49
+ test('outputs JSON for objects in human mode (fallback)', () => {
50
+ Object.defineProperty(process.stdout, 'isTTY', {
51
+ value: true,
52
+ writable: true,
53
+ });
54
+ logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
55
+ outputResult({ id: '123' });
56
+ expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
57
+ });
58
+ });
59
+
60
+ describe('outputError', () => {
61
+ let errorSpy: MockInstance;
62
+ let exitSpy: MockInstance;
63
+ const originalIsTTY = process.stdout.isTTY;
64
+
65
+ afterEach(() => {
66
+ errorSpy?.mockRestore();
67
+ exitSpy?.mockRestore();
68
+ Object.defineProperty(process.stdout, 'isTTY', {
69
+ value: originalIsTTY,
70
+ writable: true,
71
+ });
72
+ });
73
+
74
+ test('outputs JSON error when json is true', () => {
75
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
76
+ exitSpy = vi
77
+ .spyOn(process, 'exit')
78
+ .mockImplementation(() => undefined as never);
79
+
80
+ outputError({ message: 'not found', code: 'not_found' }, { json: true });
81
+
82
+ const expected = JSON.stringify(
83
+ { error: { message: 'not found', code: 'not_found' } },
84
+ null,
85
+ 2,
86
+ );
87
+ expect(errorSpy).toHaveBeenCalledWith(expected);
88
+ expect(exitSpy).toHaveBeenCalledWith(1);
89
+ });
90
+
91
+ test('outputs text error when TTY and no json flag', () => {
92
+ Object.defineProperty(process.stdout, 'isTTY', {
93
+ value: true,
94
+ writable: true,
95
+ });
96
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
97
+ exitSpy = vi
98
+ .spyOn(process, 'exit')
99
+ .mockImplementation(() => undefined as never);
100
+
101
+ outputError({ message: 'something broke' });
102
+
103
+ expect(errorSpy).toHaveBeenCalledWith(
104
+ expect.stringContaining('something broke'),
105
+ );
106
+ expect(exitSpy).toHaveBeenCalledWith(1);
107
+ });
108
+
109
+ test('uses custom exit code', () => {
110
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
111
+ exitSpy = vi
112
+ .spyOn(process, 'exit')
113
+ .mockImplementation(() => undefined as never);
114
+
115
+ outputError({ message: 'error' }, { exitCode: 2, json: true });
116
+
117
+ expect(exitSpy).toHaveBeenCalledWith(2);
118
+ });
119
+
120
+ test('defaults error code to "unknown" when not provided', () => {
121
+ Object.defineProperty(process.stdout, 'isTTY', {
122
+ value: undefined,
123
+ writable: true,
124
+ });
125
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
126
+ exitSpy = vi
127
+ .spyOn(process, 'exit')
128
+ .mockImplementation(() => undefined as never);
129
+
130
+ outputError({ message: 'oops' });
131
+
132
+ const output = errorSpy.mock.calls[0][0] as string;
133
+ const parsed = JSON.parse(output);
134
+ expect(parsed.error.code).toBe('unknown');
135
+ });
136
+ });
@@ -0,0 +1,185 @@
1
+ import {
2
+ afterEach,
3
+ describe,
4
+ expect,
5
+ type MockInstance,
6
+ test,
7
+ vi,
8
+ } from 'vitest';
9
+ import { expectExit1, mockExitThrow } from '../helpers';
10
+
11
+ describe('promptForMissing', () => {
12
+ const originalStdinIsTTY = process.stdin.isTTY;
13
+ const originalStdoutIsTTY = process.stdout.isTTY;
14
+ let errorSpy: MockInstance | undefined;
15
+ let exitSpy: MockInstance | undefined;
16
+
17
+ afterEach(() => {
18
+ errorSpy?.mockRestore();
19
+ exitSpy?.mockRestore();
20
+ errorSpy = undefined;
21
+ exitSpy = undefined;
22
+ Object.defineProperty(process.stdin, 'isTTY', {
23
+ value: originalStdinIsTTY,
24
+ writable: true,
25
+ });
26
+ Object.defineProperty(process.stdout, 'isTTY', {
27
+ value: originalStdoutIsTTY,
28
+ writable: true,
29
+ });
30
+ });
31
+
32
+ test('returns options unchanged when nothing is missing', async () => {
33
+ const { promptForMissing } = await import('../../src/lib/prompts');
34
+ const opts = { from: 'a@b.com', to: 'c@d.com', subject: 'Hi' };
35
+ const result = await promptForMissing(
36
+ opts,
37
+ [
38
+ { flag: 'from', message: 'From' },
39
+ { flag: 'to', message: 'To' },
40
+ { flag: 'subject', message: 'Subject' },
41
+ ],
42
+ {},
43
+ );
44
+ expect(result).toEqual(opts);
45
+ });
46
+
47
+ test('exits with missing_flags error in non-interactive mode', async () => {
48
+ Object.defineProperty(process.stdin, 'isTTY', {
49
+ value: undefined,
50
+ writable: true,
51
+ });
52
+ Object.defineProperty(process.stdout, 'isTTY', {
53
+ value: undefined,
54
+ writable: true,
55
+ });
56
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
57
+ exitSpy = mockExitThrow();
58
+
59
+ const { promptForMissing } = await import('../../src/lib/prompts');
60
+
61
+ await expectExit1(() =>
62
+ promptForMissing(
63
+ { from: undefined, to: 'c@d.com', subject: undefined },
64
+ [
65
+ { flag: 'from', message: 'From' },
66
+ { flag: 'to', message: 'To' },
67
+ { flag: 'subject', message: 'Subject' },
68
+ ],
69
+ {},
70
+ ),
71
+ );
72
+
73
+ const allErrors = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
74
+ expect(allErrors).toContain('--from');
75
+ expect(allErrors).toContain('--subject');
76
+ // --to should NOT be listed since it has a value
77
+ expect(allErrors).not.toContain('--to,');
78
+ });
79
+
80
+ test('errors output includes missing_flags code', async () => {
81
+ Object.defineProperty(process.stdin, 'isTTY', {
82
+ value: undefined,
83
+ writable: true,
84
+ });
85
+ Object.defineProperty(process.stdout, 'isTTY', {
86
+ value: undefined,
87
+ writable: true,
88
+ });
89
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
90
+ exitSpy = mockExitThrow();
91
+
92
+ const { promptForMissing } = await import('../../src/lib/prompts');
93
+
94
+ await expectExit1(() =>
95
+ promptForMissing(
96
+ { from: undefined },
97
+ [{ flag: 'from', message: 'From' }],
98
+ {},
99
+ ),
100
+ );
101
+
102
+ const allErrors = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
103
+ expect(allErrors).toContain('missing_flags');
104
+ });
105
+
106
+ test('skips fields marked as required=false', async () => {
107
+ const { promptForMissing } = await import('../../src/lib/prompts');
108
+ const opts = { from: 'a@b.com', to: undefined };
109
+ const result = await promptForMissing(
110
+ opts,
111
+ [
112
+ { flag: 'from', message: 'From' },
113
+ { flag: 'to', message: 'To', required: false },
114
+ ],
115
+ {},
116
+ );
117
+ expect(result).toEqual(opts);
118
+ });
119
+ });
120
+
121
+ describe('confirmDelete', () => {
122
+ const originalStdinIsTTY = process.stdin.isTTY;
123
+ const originalStdoutIsTTY = process.stdout.isTTY;
124
+ let errorSpy: MockInstance | undefined;
125
+ let exitSpy: MockInstance | undefined;
126
+
127
+ afterEach(() => {
128
+ errorSpy?.mockRestore();
129
+ exitSpy?.mockRestore();
130
+ errorSpy = undefined;
131
+ exitSpy = undefined;
132
+ Object.defineProperty(process.stdin, 'isTTY', {
133
+ value: originalStdinIsTTY,
134
+ writable: true,
135
+ });
136
+ Object.defineProperty(process.stdout, 'isTTY', {
137
+ value: originalStdoutIsTTY,
138
+ writable: true,
139
+ });
140
+ });
141
+
142
+ test('exits with confirmation_required when non-interactive', async () => {
143
+ Object.defineProperty(process.stdin, 'isTTY', {
144
+ value: undefined,
145
+ writable: true,
146
+ });
147
+ Object.defineProperty(process.stdout, 'isTTY', {
148
+ value: undefined,
149
+ writable: true,
150
+ });
151
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
152
+ exitSpy = mockExitThrow();
153
+
154
+ const { confirmDelete } = await import('../../src/lib/prompts');
155
+
156
+ await expectExit1(() =>
157
+ confirmDelete('res_123', 'Delete resource res_123?', { json: false }),
158
+ );
159
+
160
+ const output = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
161
+ expect(output).toContain('confirmation_required');
162
+ });
163
+
164
+ test('outputs JSON confirmation_required error when json option is true', async () => {
165
+ Object.defineProperty(process.stdin, 'isTTY', {
166
+ value: undefined,
167
+ writable: true,
168
+ });
169
+ Object.defineProperty(process.stdout, 'isTTY', {
170
+ value: undefined,
171
+ writable: true,
172
+ });
173
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
174
+ exitSpy = mockExitThrow();
175
+
176
+ const { confirmDelete } = await import('../../src/lib/prompts');
177
+ await expectExit1(() =>
178
+ confirmDelete('res_123', 'Delete?', { json: true }),
179
+ );
180
+
181
+ const raw = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
182
+ const parsed = JSON.parse(raw);
183
+ expect(parsed.error.code).toBe('confirmation_required');
184
+ });
185
+ });
@@ -0,0 +1,166 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ type MockInstance,
7
+ test,
8
+ vi,
9
+ } from 'vitest';
10
+
11
+ describe('createSpinner', () => {
12
+ const originalStdinIsTTY = process.stdin.isTTY;
13
+ const originalStdoutIsTTY = process.stdout.isTTY;
14
+ let stderrSpy: MockInstance;
15
+
16
+ beforeEach(() => {
17
+ vi.resetModules();
18
+ });
19
+
20
+ afterEach(() => {
21
+ stderrSpy?.mockRestore();
22
+ Object.defineProperty(process.stdin, 'isTTY', {
23
+ value: originalStdinIsTTY,
24
+ writable: true,
25
+ });
26
+ Object.defineProperty(process.stdout, 'isTTY', {
27
+ value: originalStdoutIsTTY,
28
+ writable: true,
29
+ });
30
+ delete process.env.CI;
31
+ });
32
+
33
+ test('returns no-op spinner in non-interactive mode', async () => {
34
+ Object.defineProperty(process.stdin, 'isTTY', {
35
+ value: undefined,
36
+ writable: true,
37
+ });
38
+ Object.defineProperty(process.stdout, 'isTTY', {
39
+ value: undefined,
40
+ writable: true,
41
+ });
42
+
43
+ const { createSpinner } = await import('../../src/lib/spinner');
44
+ const spinner = createSpinner('test message');
45
+
46
+ // Should not throw when calling any method
47
+ expect(() => spinner.stop('done')).not.toThrow();
48
+ expect(() => spinner.fail('error')).not.toThrow();
49
+ expect(() => spinner.warn('warning')).not.toThrow();
50
+ expect(() => spinner.update('updating')).not.toThrow();
51
+ });
52
+
53
+ test('returns functional spinner in interactive mode', async () => {
54
+ Object.defineProperty(process.stdin, 'isTTY', {
55
+ value: true,
56
+ writable: true,
57
+ });
58
+ Object.defineProperty(process.stdout, 'isTTY', {
59
+ value: true,
60
+ writable: true,
61
+ });
62
+ delete process.env.CI;
63
+ delete process.env.GITHUB_ACTIONS;
64
+ delete process.env.TERM;
65
+
66
+ stderrSpy = vi
67
+ .spyOn(process.stderr, 'write')
68
+ .mockImplementation(() => true);
69
+
70
+ const { createSpinner } = await import('../../src/lib/spinner');
71
+ const spinner = createSpinner('loading...');
72
+
73
+ expect(spinner).toHaveProperty('stop');
74
+ expect(spinner).toHaveProperty('fail');
75
+ expect(spinner).toHaveProperty('warn');
76
+ expect(spinner).toHaveProperty('update');
77
+
78
+ // Stop to clean up the interval
79
+ spinner.stop('done');
80
+ expect(stderrSpy).toHaveBeenCalled();
81
+ });
82
+
83
+ test('stop writes checkmark to stderr', async () => {
84
+ Object.defineProperty(process.stdin, 'isTTY', {
85
+ value: true,
86
+ writable: true,
87
+ });
88
+ Object.defineProperty(process.stdout, 'isTTY', {
89
+ value: true,
90
+ writable: true,
91
+ });
92
+ delete process.env.CI;
93
+ delete process.env.GITHUB_ACTIONS;
94
+ delete process.env.TERM;
95
+
96
+ stderrSpy = vi
97
+ .spyOn(process.stderr, 'write')
98
+ .mockImplementation(() => true);
99
+
100
+ const { createSpinner } = await import('../../src/lib/spinner');
101
+ const spinner = createSpinner('loading...');
102
+ spinner.stop('completed');
103
+
104
+ const lastCall = stderrSpy.mock.calls[
105
+ stderrSpy.mock.calls.length - 1
106
+ ][0] as string;
107
+ expect(lastCall).toContain('✔');
108
+ expect(lastCall).toContain('completed');
109
+ });
110
+
111
+ test('fail writes cross mark to stderr', async () => {
112
+ Object.defineProperty(process.stdin, 'isTTY', {
113
+ value: true,
114
+ writable: true,
115
+ });
116
+ Object.defineProperty(process.stdout, 'isTTY', {
117
+ value: true,
118
+ writable: true,
119
+ });
120
+ delete process.env.CI;
121
+ delete process.env.GITHUB_ACTIONS;
122
+ delete process.env.TERM;
123
+
124
+ stderrSpy = vi
125
+ .spyOn(process.stderr, 'write')
126
+ .mockImplementation(() => true);
127
+
128
+ const { createSpinner } = await import('../../src/lib/spinner');
129
+ const spinner = createSpinner('loading...');
130
+ spinner.fail('error occurred');
131
+
132
+ const lastCall = stderrSpy.mock.calls[
133
+ stderrSpy.mock.calls.length - 1
134
+ ][0] as string;
135
+ expect(lastCall).toContain('✗');
136
+ expect(lastCall).toContain('error occurred');
137
+ });
138
+
139
+ test('warn writes warning icon to stderr', async () => {
140
+ Object.defineProperty(process.stdin, 'isTTY', {
141
+ value: true,
142
+ writable: true,
143
+ });
144
+ Object.defineProperty(process.stdout, 'isTTY', {
145
+ value: true,
146
+ writable: true,
147
+ });
148
+ delete process.env.CI;
149
+ delete process.env.GITHUB_ACTIONS;
150
+ delete process.env.TERM;
151
+
152
+ stderrSpy = vi
153
+ .spyOn(process.stderr, 'write')
154
+ .mockImplementation(() => true);
155
+
156
+ const { createSpinner } = await import('../../src/lib/spinner');
157
+ const spinner = createSpinner('loading...');
158
+ spinner.warn('watch out');
159
+
160
+ const lastCall = stderrSpy.mock.calls[
161
+ stderrSpy.mock.calls.length - 1
162
+ ][0] as string;
163
+ expect(lastCall).toContain('⚠');
164
+ expect(lastCall).toContain('watch out');
165
+ });
166
+ });
@@ -0,0 +1,63 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { renderTable } from '../../src/lib/table';
3
+
4
+ describe('renderTable', () => {
5
+ test('renders a table with correct border characters', () => {
6
+ const output = renderTable(['Name', 'ID'], [['Alice', 'abc-123']]);
7
+ expect(output).toContain('┌');
8
+ expect(output).toContain('┐');
9
+ expect(output).toContain('└');
10
+ expect(output).toContain('┘');
11
+ expect(output).toContain('│');
12
+ });
13
+
14
+ test('includes headers in output', () => {
15
+ const output = renderTable(
16
+ ['Name', 'Status'],
17
+ [['my-domain.com', 'verified']],
18
+ );
19
+ expect(output).toContain('Name');
20
+ expect(output).toContain('Status');
21
+ });
22
+
23
+ test('includes row data in output', () => {
24
+ const output = renderTable(
25
+ ['Name', 'Status'],
26
+ [['my-domain.com', 'verified']],
27
+ );
28
+ expect(output).toContain('my-domain.com');
29
+ expect(output).toContain('verified');
30
+ });
31
+
32
+ test('pads columns to the widest cell in each column', () => {
33
+ const output = renderTable(
34
+ ['Key', 'Value'],
35
+ [
36
+ ['short', 'a very long value here'],
37
+ ['much longer key', 'v'],
38
+ ],
39
+ );
40
+ // All rows should have the same line length
41
+ const lines = output.split('\n');
42
+ const lengths = lines.map((l) => l.length);
43
+ expect(new Set(lengths).size).toBe(1);
44
+ });
45
+
46
+ test('renders multiple rows', () => {
47
+ const output = renderTable(
48
+ ['A', 'B'],
49
+ [
50
+ ['row1a', 'row1b'],
51
+ ['row2a', 'row2b'],
52
+ ],
53
+ );
54
+ expect(output).toContain('row1a');
55
+ expect(output).toContain('row2a');
56
+ });
57
+
58
+ test('contains a separator row between header and data', () => {
59
+ const output = renderTable(['Col'], [['val']]);
60
+ expect(output).toContain('├');
61
+ expect(output).toContain('┤');
62
+ });
63
+ });
@@ -0,0 +1,89 @@
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
2
+ import { captureTestEnv } from '../helpers';
3
+
4
+ // We need to import the module fresh per test to pick up env changes,
5
+ // so we use dynamic imports.
6
+
7
+ describe('isInteractive', () => {
8
+ const restoreEnv = captureTestEnv();
9
+
10
+ beforeEach(() => {
11
+ vi.resetModules();
12
+ });
13
+
14
+ afterEach(() => {
15
+ restoreEnv();
16
+ });
17
+
18
+ function setTTY(stdin: boolean, stdout: boolean) {
19
+ Object.defineProperty(process.stdin, 'isTTY', {
20
+ value: stdin ? true : undefined,
21
+ writable: true,
22
+ });
23
+ Object.defineProperty(process.stdout, 'isTTY', {
24
+ value: stdout ? true : undefined,
25
+ writable: true,
26
+ });
27
+ }
28
+
29
+ test('returns true when stdin and stdout are TTY and no CI env', async () => {
30
+ setTTY(true, true);
31
+ delete process.env.CI;
32
+ delete process.env.GITHUB_ACTIONS;
33
+ delete process.env.TERM;
34
+
35
+ const { isInteractive } = await import('../../src/lib/tty');
36
+ expect(isInteractive()).toBe(true);
37
+ });
38
+
39
+ test('returns false when stdin is not TTY', async () => {
40
+ setTTY(false, true);
41
+ delete process.env.CI;
42
+
43
+ const { isInteractive } = await import('../../src/lib/tty');
44
+ expect(isInteractive()).toBe(false);
45
+ });
46
+
47
+ test('returns false when stdout is not TTY', async () => {
48
+ setTTY(true, false);
49
+ delete process.env.CI;
50
+
51
+ const { isInteractive } = await import('../../src/lib/tty');
52
+ expect(isInteractive()).toBe(false);
53
+ });
54
+
55
+ test('returns false when CI=true', async () => {
56
+ setTTY(true, true);
57
+ process.env.CI = 'true';
58
+
59
+ const { isInteractive } = await import('../../src/lib/tty');
60
+ expect(isInteractive()).toBe(false);
61
+ });
62
+
63
+ test('returns false when CI=1', async () => {
64
+ setTTY(true, true);
65
+ process.env.CI = '1';
66
+
67
+ const { isInteractive } = await import('../../src/lib/tty');
68
+ expect(isInteractive()).toBe(false);
69
+ });
70
+
71
+ test('returns false when GITHUB_ACTIONS is set', async () => {
72
+ setTTY(true, true);
73
+ delete process.env.CI;
74
+ process.env.GITHUB_ACTIONS = 'true';
75
+
76
+ const { isInteractive } = await import('../../src/lib/tty');
77
+ expect(isInteractive()).toBe(false);
78
+ });
79
+
80
+ test('returns false when TERM=dumb', async () => {
81
+ setTTY(true, true);
82
+ delete process.env.CI;
83
+ delete process.env.GITHUB_ACTIONS;
84
+ process.env.TERM = 'dumb';
85
+
86
+ const { isInteractive } = await import('../../src/lib/tty');
87
+ expect(isInteractive()).toBe(false);
88
+ });
89
+ });