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,217 @@
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 mockUpdate = vi.fn(async () => ({
20
+ data: {
21
+ object: 'contact_property' as const,
22
+ id: 'b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d',
23
+ },
24
+ error: null,
25
+ }));
26
+
27
+ vi.mock('resend', () => ({
28
+ Resend: class MockResend {
29
+ constructor(public key: string) {}
30
+ contactProperties = { update: mockUpdate };
31
+ },
32
+ }));
33
+
34
+ describe('contact-properties update command', () => {
35
+ const restoreEnv = captureTestEnv();
36
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
37
+ let errorSpy: MockInstance | undefined;
38
+ let stderrSpy: MockInstance | undefined;
39
+ let exitSpy: MockInstance | undefined;
40
+
41
+ beforeEach(() => {
42
+ process.env.RESEND_API_KEY = 're_test_key';
43
+ mockUpdate.mockClear();
44
+ });
45
+
46
+ afterEach(() => {
47
+ restoreEnv();
48
+ errorSpy?.mockRestore();
49
+ stderrSpy?.mockRestore();
50
+ exitSpy?.mockRestore();
51
+ spies = undefined;
52
+ errorSpy = undefined;
53
+ stderrSpy = undefined;
54
+ exitSpy = undefined;
55
+ });
56
+
57
+ test('updates property fallback value', async () => {
58
+ spies = setupOutputSpies();
59
+
60
+ const { updateContactPropertyCommand } = await import(
61
+ '../../../src/commands/contact-properties/update'
62
+ );
63
+ await updateContactPropertyCommand.parseAsync(
64
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d', '--fallback-value', 'Acme Corp'],
65
+ { from: 'user' },
66
+ );
67
+
68
+ expect(mockUpdate).toHaveBeenCalledTimes(1);
69
+ const args = mockUpdate.mock.calls[0][0] as Record<string, unknown>;
70
+ expect(args.id).toBe('b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d');
71
+ expect(args.fallbackValue).toBe('Acme Corp');
72
+ });
73
+
74
+ test('clears fallback value with --clear-fallback-value', async () => {
75
+ spies = setupOutputSpies();
76
+
77
+ const { updateContactPropertyCommand } = await import(
78
+ '../../../src/commands/contact-properties/update'
79
+ );
80
+ await updateContactPropertyCommand.parseAsync(
81
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d', '--clear-fallback-value'],
82
+ { from: 'user' },
83
+ );
84
+
85
+ const args = mockUpdate.mock.calls[0][0] as Record<string, unknown>;
86
+ expect(args.id).toBe('b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d');
87
+ expect(args.fallbackValue).toBeNull();
88
+ });
89
+
90
+ test('errors with conflicting_flags when both --fallback-value and --clear-fallback-value are given', async () => {
91
+ setNonInteractive();
92
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
93
+ exitSpy = mockExitThrow();
94
+
95
+ const { updateContactPropertyCommand } = await import(
96
+ '../../../src/commands/contact-properties/update'
97
+ );
98
+ await expectExit1(() =>
99
+ updateContactPropertyCommand.parseAsync(
100
+ [
101
+ 'b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d',
102
+ '--fallback-value',
103
+ 'Acme',
104
+ '--clear-fallback-value',
105
+ ],
106
+ { from: 'user' },
107
+ ),
108
+ );
109
+
110
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
111
+ expect(output).toContain('conflicting_flags');
112
+ });
113
+
114
+ test('outputs JSON result when non-interactive', async () => {
115
+ spies = setupOutputSpies();
116
+
117
+ const { updateContactPropertyCommand } = await import(
118
+ '../../../src/commands/contact-properties/update'
119
+ );
120
+ await updateContactPropertyCommand.parseAsync(
121
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d', '--fallback-value', 'Test'],
122
+ { from: 'user' },
123
+ );
124
+
125
+ const output = spies.logSpy.mock.calls[0][0] as string;
126
+ const parsed = JSON.parse(output);
127
+ expect(parsed.object).toBe('contact_property');
128
+ expect(parsed.id).toBe('b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d');
129
+ });
130
+
131
+ test('errors with no_changes when no flags are provided', async () => {
132
+ setNonInteractive();
133
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
134
+ exitSpy = mockExitThrow();
135
+
136
+ const { updateContactPropertyCommand } = await import(
137
+ '../../../src/commands/contact-properties/update'
138
+ );
139
+ await expectExit1(() =>
140
+ updateContactPropertyCommand.parseAsync(
141
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d'],
142
+ {
143
+ from: 'user',
144
+ },
145
+ ),
146
+ );
147
+
148
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
149
+ expect(output).toContain('no_changes');
150
+ });
151
+
152
+ test('does not call SDK when no_changes error is raised', async () => {
153
+ setNonInteractive();
154
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
155
+ exitSpy = mockExitThrow();
156
+
157
+ const { updateContactPropertyCommand } = await import(
158
+ '../../../src/commands/contact-properties/update'
159
+ );
160
+ await expectExit1(() =>
161
+ updateContactPropertyCommand.parseAsync(
162
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d'],
163
+ {
164
+ from: 'user',
165
+ },
166
+ ),
167
+ );
168
+
169
+ expect(mockUpdate).not.toHaveBeenCalled();
170
+ });
171
+
172
+ test('errors with auth_error when no API key', async () => {
173
+ setNonInteractive();
174
+ delete process.env.RESEND_API_KEY;
175
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
176
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
177
+ exitSpy = mockExitThrow();
178
+
179
+ const { updateContactPropertyCommand } = await import(
180
+ '../../../src/commands/contact-properties/update'
181
+ );
182
+ await expectExit1(() =>
183
+ updateContactPropertyCommand.parseAsync(
184
+ ['b4a3c2d1-6e5f-8a7b-0c9d-2e1f4a3b6c5d', '--fallback-value', 'Test'],
185
+ { from: 'user' },
186
+ ),
187
+ );
188
+
189
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
190
+ expect(output).toContain('auth_error');
191
+ });
192
+
193
+ test('errors with update_error when SDK returns an error', async () => {
194
+ setNonInteractive();
195
+ mockUpdate.mockResolvedValueOnce(
196
+ mockSdkError('Property not found', 'not_found'),
197
+ );
198
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
199
+ stderrSpy = vi
200
+ .spyOn(process.stderr, 'write')
201
+ .mockImplementation(() => true);
202
+ exitSpy = mockExitThrow();
203
+
204
+ const { updateContactPropertyCommand } = await import(
205
+ '../../../src/commands/contact-properties/update'
206
+ );
207
+ await expectExit1(() =>
208
+ updateContactPropertyCommand.parseAsync(
209
+ ['nonexistent_id', '--fallback-value', 'Test'],
210
+ { from: 'user' },
211
+ ),
212
+ );
213
+
214
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
215
+ expect(output).toContain('update_error');
216
+ });
217
+ });
@@ -0,0 +1,189 @@
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 mockAddSegment = vi.fn(async () => ({
20
+ data: { id: '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d' },
21
+ error: null,
22
+ }));
23
+
24
+ vi.mock('resend', () => ({
25
+ Resend: class MockResend {
26
+ constructor(public key: string) {}
27
+ contacts = {
28
+ segments: { add: mockAddSegment },
29
+ };
30
+ },
31
+ }));
32
+
33
+ describe('contacts add-segment command', () => {
34
+ const restoreEnv = captureTestEnv();
35
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
36
+ let errorSpy: MockInstance | undefined;
37
+ let stderrSpy: MockInstance | undefined;
38
+ let exitSpy: MockInstance | undefined;
39
+
40
+ beforeEach(() => {
41
+ process.env.RESEND_API_KEY = 're_test_key';
42
+ mockAddSegment.mockClear();
43
+ });
44
+
45
+ afterEach(() => {
46
+ restoreEnv();
47
+ errorSpy?.mockRestore();
48
+ stderrSpy?.mockRestore();
49
+ exitSpy?.mockRestore();
50
+ spies = undefined;
51
+ errorSpy = undefined;
52
+ stderrSpy = undefined;
53
+ exitSpy = undefined;
54
+ });
55
+
56
+ test('adds contact to segment by contact ID', async () => {
57
+ spies = setupOutputSpies();
58
+
59
+ const { addContactSegmentCommand } = await import(
60
+ '../../../src/commands/contacts/add-segment'
61
+ );
62
+ await addContactSegmentCommand.parseAsync(
63
+ [
64
+ 'a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
65
+ '--segment-id',
66
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
67
+ ],
68
+ { from: 'user' },
69
+ );
70
+
71
+ expect(mockAddSegment).toHaveBeenCalledTimes(1);
72
+ const args = mockAddSegment.mock.calls[0][0] as Record<string, unknown>;
73
+ expect(args.contactId).toBe('a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6');
74
+ expect(args.segmentId).toBe('7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d');
75
+ });
76
+
77
+ test('adds contact to segment by email', async () => {
78
+ spies = setupOutputSpies();
79
+
80
+ const { addContactSegmentCommand } = await import(
81
+ '../../../src/commands/contacts/add-segment'
82
+ );
83
+ await addContactSegmentCommand.parseAsync(
84
+ [
85
+ 'jane@example.com',
86
+ '--segment-id',
87
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
88
+ ],
89
+ { from: 'user' },
90
+ );
91
+
92
+ const args = mockAddSegment.mock.calls[0][0] as Record<string, unknown>;
93
+ expect(args.email).toBe('jane@example.com');
94
+ expect(args.segmentId).toBe('7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d');
95
+ });
96
+
97
+ test('outputs JSON result when non-interactive', async () => {
98
+ spies = setupOutputSpies();
99
+
100
+ const { addContactSegmentCommand } = await import(
101
+ '../../../src/commands/contacts/add-segment'
102
+ );
103
+ await addContactSegmentCommand.parseAsync(
104
+ [
105
+ 'a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
106
+ '--segment-id',
107
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
108
+ ],
109
+ { from: 'user' },
110
+ );
111
+
112
+ const output = spies.logSpy.mock.calls[0][0] as string;
113
+ const parsed = JSON.parse(output);
114
+ expect(parsed.id).toBe('7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d');
115
+ });
116
+
117
+ test('errors with missing_segment_id when --segment-id absent in non-interactive mode', async () => {
118
+ setNonInteractive();
119
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
120
+ exitSpy = mockExitThrow();
121
+
122
+ const { addContactSegmentCommand } = await import(
123
+ '../../../src/commands/contacts/add-segment'
124
+ );
125
+ await expectExit1(() =>
126
+ addContactSegmentCommand.parseAsync(
127
+ ['a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6'],
128
+ { from: 'user' },
129
+ ),
130
+ );
131
+
132
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
133
+ expect(output).toContain('missing_segment_id');
134
+ });
135
+
136
+ test('errors with auth_error when no API key', async () => {
137
+ setNonInteractive();
138
+ delete process.env.RESEND_API_KEY;
139
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
140
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
141
+ exitSpy = mockExitThrow();
142
+
143
+ const { addContactSegmentCommand } = await import(
144
+ '../../../src/commands/contacts/add-segment'
145
+ );
146
+ await expectExit1(() =>
147
+ addContactSegmentCommand.parseAsync(
148
+ [
149
+ 'a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
150
+ '--segment-id',
151
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
152
+ ],
153
+ { from: 'user' },
154
+ ),
155
+ );
156
+
157
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
158
+ expect(output).toContain('auth_error');
159
+ });
160
+
161
+ test('errors with add_segment_error when SDK returns an error', async () => {
162
+ setNonInteractive();
163
+ mockAddSegment.mockResolvedValueOnce(
164
+ mockSdkError('Segment not found', 'not_found'),
165
+ );
166
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
167
+ stderrSpy = vi
168
+ .spyOn(process.stderr, 'write')
169
+ .mockImplementation(() => true);
170
+ exitSpy = mockExitThrow();
171
+
172
+ const { addContactSegmentCommand } = await import(
173
+ '../../../src/commands/contacts/add-segment'
174
+ );
175
+ await expectExit1(() =>
176
+ addContactSegmentCommand.parseAsync(
177
+ [
178
+ 'a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
179
+ '--segment-id',
180
+ '00000000-0000-0000-0000-00000bad0seg',
181
+ ],
182
+ { from: 'user' },
183
+ ),
184
+ );
185
+
186
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
187
+ expect(output).toContain('add_segment_error');
188
+ });
189
+ });
@@ -0,0 +1,271 @@
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: 'contact' as const,
22
+ id: 'a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6',
23
+ },
24
+ error: null,
25
+ }));
26
+
27
+ vi.mock('resend', () => ({
28
+ Resend: class MockResend {
29
+ constructor(public key: string) {}
30
+ contacts = { create: mockCreate };
31
+ },
32
+ }));
33
+
34
+ describe('contacts create command', () => {
35
+ const restoreEnv = captureTestEnv();
36
+ let spies: ReturnType<typeof setupOutputSpies> | undefined;
37
+ let errorSpy: MockInstance | undefined;
38
+ let stderrSpy: MockInstance | undefined;
39
+ let exitSpy: MockInstance | undefined;
40
+
41
+ beforeEach(() => {
42
+ process.env.RESEND_API_KEY = 're_test_key';
43
+ mockCreate.mockClear();
44
+ });
45
+
46
+ afterEach(() => {
47
+ restoreEnv();
48
+ errorSpy?.mockRestore();
49
+ stderrSpy?.mockRestore();
50
+ exitSpy?.mockRestore();
51
+ spies = undefined;
52
+ errorSpy = undefined;
53
+ stderrSpy = undefined;
54
+ exitSpy = undefined;
55
+ });
56
+
57
+ test('creates contact with --email flag', async () => {
58
+ spies = setupOutputSpies();
59
+
60
+ const { createContactCommand } = await import(
61
+ '../../../src/commands/contacts/create'
62
+ );
63
+ await createContactCommand.parseAsync(['--email', 'jane@example.com'], {
64
+ from: 'user',
65
+ });
66
+
67
+ expect(mockCreate).toHaveBeenCalledTimes(1);
68
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
69
+ expect(args.email).toBe('jane@example.com');
70
+ });
71
+
72
+ test('outputs JSON id when non-interactive', async () => {
73
+ spies = setupOutputSpies();
74
+
75
+ const { createContactCommand } = await import(
76
+ '../../../src/commands/contacts/create'
77
+ );
78
+ await createContactCommand.parseAsync(['--email', 'jane@example.com'], {
79
+ from: 'user',
80
+ });
81
+
82
+ const output = spies.logSpy.mock.calls[0][0] as string;
83
+ const parsed = JSON.parse(output);
84
+ expect(parsed.id).toBe('a1b2c3d4-5e6f-7a8b-9c0d-e1f2a3b4c5d6');
85
+ expect(parsed.object).toBe('contact');
86
+ });
87
+
88
+ test('passes --first-name and --last-name to SDK', async () => {
89
+ spies = setupOutputSpies();
90
+
91
+ const { createContactCommand } = await import(
92
+ '../../../src/commands/contacts/create'
93
+ );
94
+ await createContactCommand.parseAsync(
95
+ [
96
+ '--email',
97
+ 'jane@example.com',
98
+ '--first-name',
99
+ 'Jane',
100
+ '--last-name',
101
+ 'Smith',
102
+ ],
103
+ { from: 'user' },
104
+ );
105
+
106
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
107
+ expect(args.firstName).toBe('Jane');
108
+ expect(args.lastName).toBe('Smith');
109
+ });
110
+
111
+ test('passes --unsubscribed flag to SDK', async () => {
112
+ spies = setupOutputSpies();
113
+
114
+ const { createContactCommand } = await import(
115
+ '../../../src/commands/contacts/create'
116
+ );
117
+ await createContactCommand.parseAsync(
118
+ ['--email', 'jane@example.com', '--unsubscribed'],
119
+ { from: 'user' },
120
+ );
121
+
122
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
123
+ expect(args.unsubscribed).toBe(true);
124
+ });
125
+
126
+ test('parses --properties JSON and passes to SDK', async () => {
127
+ spies = setupOutputSpies();
128
+
129
+ const { createContactCommand } = await import(
130
+ '../../../src/commands/contacts/create'
131
+ );
132
+ await createContactCommand.parseAsync(
133
+ [
134
+ '--email',
135
+ 'jane@example.com',
136
+ '--properties',
137
+ '{"company":"Acme","plan":"pro"}',
138
+ ],
139
+ { from: 'user' },
140
+ );
141
+
142
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
143
+ expect(args.properties).toEqual({ company: 'Acme', plan: 'pro' });
144
+ });
145
+
146
+ test('passes --segment-id (single) to SDK as segments array', async () => {
147
+ spies = setupOutputSpies();
148
+
149
+ const { createContactCommand } = await import(
150
+ '../../../src/commands/contacts/create'
151
+ );
152
+ await createContactCommand.parseAsync(
153
+ [
154
+ '--email',
155
+ 'jane@example.com',
156
+ '--segment-id',
157
+ '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d',
158
+ ],
159
+ { from: 'user' },
160
+ );
161
+
162
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
163
+ expect(args.segments).toEqual([
164
+ { id: '7b1e0a3d-4c5f-4e8a-9b2d-1a3c5e7f9b2d' },
165
+ ]);
166
+ });
167
+
168
+ test('passes multiple --segment-id values to SDK', async () => {
169
+ spies = setupOutputSpies();
170
+
171
+ const { createContactCommand } = await import(
172
+ '../../../src/commands/contacts/create'
173
+ );
174
+ await createContactCommand.parseAsync(
175
+ [
176
+ '--email',
177
+ 'jane@example.com',
178
+ '--segment-id',
179
+ '3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c',
180
+ '--segment-id',
181
+ 'e8d7c6b5-a4f3-2e1d-0c9b-8a7f6e5d4c3b',
182
+ ],
183
+ { from: 'user' },
184
+ );
185
+
186
+ const args = mockCreate.mock.calls[0][0] as Record<string, unknown>;
187
+ expect(args.segments).toEqual([
188
+ { id: '3f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c' },
189
+ { id: 'e8d7c6b5-a4f3-2e1d-0c9b-8a7f6e5d4c3b' },
190
+ ]);
191
+ });
192
+
193
+ test('errors with missing_email in non-interactive mode', async () => {
194
+ setNonInteractive();
195
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
196
+ exitSpy = mockExitThrow();
197
+
198
+ const { createContactCommand } = await import(
199
+ '../../../src/commands/contacts/create'
200
+ );
201
+ await expectExit1(() =>
202
+ createContactCommand.parseAsync([], { from: 'user' }),
203
+ );
204
+
205
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
206
+ expect(output).toContain('missing_email');
207
+ });
208
+
209
+ test('errors with invalid_properties when --properties is not valid JSON', async () => {
210
+ setNonInteractive();
211
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
212
+ exitSpy = mockExitThrow();
213
+
214
+ const { createContactCommand } = await import(
215
+ '../../../src/commands/contacts/create'
216
+ );
217
+ await expectExit1(() =>
218
+ createContactCommand.parseAsync(
219
+ ['--email', 'jane@example.com', '--properties', 'not-json'],
220
+ { from: 'user' },
221
+ ),
222
+ );
223
+
224
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
225
+ expect(output).toContain('invalid_properties');
226
+ });
227
+
228
+ test('errors with auth_error when no API key', async () => {
229
+ setNonInteractive();
230
+ delete process.env.RESEND_API_KEY;
231
+ process.env.XDG_CONFIG_HOME = '/tmp/nonexistent-resend';
232
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
233
+ exitSpy = mockExitThrow();
234
+
235
+ const { createContactCommand } = await import(
236
+ '../../../src/commands/contacts/create'
237
+ );
238
+ await expectExit1(() =>
239
+ createContactCommand.parseAsync(['--email', 'jane@example.com'], {
240
+ from: 'user',
241
+ }),
242
+ );
243
+
244
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
245
+ expect(output).toContain('auth_error');
246
+ });
247
+
248
+ test('errors with create_error when SDK returns an error', async () => {
249
+ setNonInteractive();
250
+ mockCreate.mockResolvedValueOnce(
251
+ mockSdkError('Contact already exists', 'validation_error'),
252
+ );
253
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
254
+ stderrSpy = vi
255
+ .spyOn(process.stderr, 'write')
256
+ .mockImplementation(() => true);
257
+ exitSpy = mockExitThrow();
258
+
259
+ const { createContactCommand } = await import(
260
+ '../../../src/commands/contacts/create'
261
+ );
262
+ await expectExit1(() =>
263
+ createContactCommand.parseAsync(['--email', 'jane@example.com'], {
264
+ from: 'user',
265
+ }),
266
+ );
267
+
268
+ const output = errorSpy.mock.calls.map((c) => c[0]).join(' ');
269
+ expect(output).toContain('create_error');
270
+ });
271
+ });