resend-cli 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +25 -10
  2. package/dist/cli.cjs +539 -0
  3. package/package.json +31 -12
  4. package/.claude/settings.local.json +0 -5
  5. package/.github/scripts/pr-title-check.js +0 -34
  6. package/.github/workflows/ci.yml +0 -32
  7. package/.github/workflows/pr-title-check.yml +0 -13
  8. package/.github/workflows/release.yml +0 -120
  9. package/.github/workflows/test-install-windows.yml +0 -48
  10. package/CHANGELOG.md +0 -31
  11. package/biome.json +0 -36
  12. package/bun.lock +0 -73
  13. package/bunfig.toml +0 -2
  14. package/docs/agent-dx-gaps.md +0 -167
  15. package/docs/missing-commands.md +0 -58
  16. package/docs/production-readiness.md +0 -99
  17. package/docs/secure-key-storage.md +0 -174
  18. package/install.ps1 +0 -141
  19. package/install.sh +0 -301
  20. package/renovate.json +0 -4
  21. package/src/cli.ts +0 -92
  22. package/src/commands/api-keys/create.ts +0 -114
  23. package/src/commands/api-keys/delete.ts +0 -47
  24. package/src/commands/api-keys/index.ts +0 -26
  25. package/src/commands/api-keys/list.ts +0 -35
  26. package/src/commands/api-keys/utils.ts +0 -8
  27. package/src/commands/auth/index.ts +0 -20
  28. package/src/commands/auth/login.ts +0 -234
  29. package/src/commands/auth/logout.ts +0 -105
  30. package/src/commands/broadcasts/create.ts +0 -196
  31. package/src/commands/broadcasts/delete.ts +0 -46
  32. package/src/commands/broadcasts/get.ts +0 -59
  33. package/src/commands/broadcasts/index.ts +0 -43
  34. package/src/commands/broadcasts/list.ts +0 -60
  35. package/src/commands/broadcasts/send.ts +0 -56
  36. package/src/commands/broadcasts/update.ts +0 -95
  37. package/src/commands/broadcasts/utils.ts +0 -35
  38. package/src/commands/contact-properties/create.ts +0 -118
  39. package/src/commands/contact-properties/delete.ts +0 -48
  40. package/src/commands/contact-properties/get.ts +0 -46
  41. package/src/commands/contact-properties/index.ts +0 -48
  42. package/src/commands/contact-properties/list.ts +0 -68
  43. package/src/commands/contact-properties/update.ts +0 -88
  44. package/src/commands/contact-properties/utils.ts +0 -17
  45. package/src/commands/contacts/add-segment.ts +0 -78
  46. package/src/commands/contacts/create.ts +0 -122
  47. package/src/commands/contacts/delete.ts +0 -49
  48. package/src/commands/contacts/get.ts +0 -53
  49. package/src/commands/contacts/index.ts +0 -58
  50. package/src/commands/contacts/list.ts +0 -57
  51. package/src/commands/contacts/remove-segment.ts +0 -48
  52. package/src/commands/contacts/segments.ts +0 -39
  53. package/src/commands/contacts/topics.ts +0 -45
  54. package/src/commands/contacts/update-topics.ts +0 -90
  55. package/src/commands/contacts/update.ts +0 -77
  56. package/src/commands/contacts/utils.ts +0 -119
  57. package/src/commands/doctor.ts +0 -216
  58. package/src/commands/domains/create.ts +0 -83
  59. package/src/commands/domains/delete.ts +0 -42
  60. package/src/commands/domains/get.ts +0 -47
  61. package/src/commands/domains/index.ts +0 -35
  62. package/src/commands/domains/list.ts +0 -53
  63. package/src/commands/domains/update.ts +0 -75
  64. package/src/commands/domains/utils.ts +0 -44
  65. package/src/commands/domains/verify.ts +0 -38
  66. package/src/commands/emails/batch.ts +0 -140
  67. package/src/commands/emails/index.ts +0 -24
  68. package/src/commands/emails/receiving/attachment.ts +0 -55
  69. package/src/commands/emails/receiving/attachments.ts +0 -68
  70. package/src/commands/emails/receiving/get.ts +0 -58
  71. package/src/commands/emails/receiving/index.ts +0 -28
  72. package/src/commands/emails/receiving/list.ts +0 -59
  73. package/src/commands/emails/receiving/utils.ts +0 -38
  74. package/src/commands/emails/send.ts +0 -189
  75. package/src/commands/open.ts +0 -24
  76. package/src/commands/segments/create.ts +0 -50
  77. package/src/commands/segments/delete.ts +0 -47
  78. package/src/commands/segments/get.ts +0 -38
  79. package/src/commands/segments/index.ts +0 -36
  80. package/src/commands/segments/list.ts +0 -58
  81. package/src/commands/segments/utils.ts +0 -7
  82. package/src/commands/teams/index.ts +0 -10
  83. package/src/commands/teams/list.ts +0 -35
  84. package/src/commands/teams/remove.ts +0 -86
  85. package/src/commands/teams/switch.ts +0 -76
  86. package/src/commands/topics/create.ts +0 -73
  87. package/src/commands/topics/delete.ts +0 -47
  88. package/src/commands/topics/get.ts +0 -42
  89. package/src/commands/topics/index.ts +0 -42
  90. package/src/commands/topics/list.ts +0 -34
  91. package/src/commands/topics/update.ts +0 -59
  92. package/src/commands/topics/utils.ts +0 -16
  93. package/src/commands/webhooks/create.ts +0 -128
  94. package/src/commands/webhooks/delete.ts +0 -49
  95. package/src/commands/webhooks/get.ts +0 -42
  96. package/src/commands/webhooks/index.ts +0 -44
  97. package/src/commands/webhooks/list.ts +0 -55
  98. package/src/commands/webhooks/update.ts +0 -83
  99. package/src/commands/webhooks/utils.ts +0 -36
  100. package/src/commands/whoami.ts +0 -71
  101. package/src/lib/actions.ts +0 -157
  102. package/src/lib/client.ts +0 -37
  103. package/src/lib/config.ts +0 -217
  104. package/src/lib/files.ts +0 -15
  105. package/src/lib/help-text.ts +0 -38
  106. package/src/lib/output.ts +0 -54
  107. package/src/lib/pagination.ts +0 -36
  108. package/src/lib/prompts.ts +0 -149
  109. package/src/lib/spinner.ts +0 -100
  110. package/src/lib/table.ts +0 -57
  111. package/src/lib/tty.ts +0 -28
  112. package/src/lib/update-check.ts +0 -172
  113. package/src/lib/version.ts +0 -4
  114. package/tests/commands/api-keys/create.test.ts +0 -195
  115. package/tests/commands/api-keys/delete.test.ts +0 -156
  116. package/tests/commands/api-keys/list.test.ts +0 -133
  117. package/tests/commands/auth/login.test.ts +0 -156
  118. package/tests/commands/auth/logout.test.ts +0 -146
  119. package/tests/commands/broadcasts/create.test.ts +0 -447
  120. package/tests/commands/broadcasts/delete.test.ts +0 -182
  121. package/tests/commands/broadcasts/get.test.ts +0 -146
  122. package/tests/commands/broadcasts/list.test.ts +0 -196
  123. package/tests/commands/broadcasts/send.test.ts +0 -161
  124. package/tests/commands/broadcasts/update.test.ts +0 -283
  125. package/tests/commands/contact-properties/create.test.ts +0 -250
  126. package/tests/commands/contact-properties/delete.test.ts +0 -183
  127. package/tests/commands/contact-properties/get.test.ts +0 -144
  128. package/tests/commands/contact-properties/list.test.ts +0 -180
  129. package/tests/commands/contact-properties/update.test.ts +0 -216
  130. package/tests/commands/contacts/add-segment.test.ts +0 -188
  131. package/tests/commands/contacts/create.test.ts +0 -270
  132. package/tests/commands/contacts/delete.test.ts +0 -192
  133. package/tests/commands/contacts/get.test.ts +0 -148
  134. package/tests/commands/contacts/list.test.ts +0 -175
  135. package/tests/commands/contacts/remove-segment.test.ts +0 -166
  136. package/tests/commands/contacts/segments.test.ts +0 -167
  137. package/tests/commands/contacts/topics.test.ts +0 -163
  138. package/tests/commands/contacts/update-topics.test.ts +0 -247
  139. package/tests/commands/contacts/update.test.ts +0 -205
  140. package/tests/commands/doctor.test.ts +0 -165
  141. package/tests/commands/domains/create.test.ts +0 -192
  142. package/tests/commands/domains/delete.test.ts +0 -156
  143. package/tests/commands/domains/get.test.ts +0 -137
  144. package/tests/commands/domains/list.test.ts +0 -164
  145. package/tests/commands/domains/update.test.ts +0 -223
  146. package/tests/commands/domains/verify.test.ts +0 -117
  147. package/tests/commands/emails/batch.test.ts +0 -313
  148. package/tests/commands/emails/receiving/attachment.test.ts +0 -140
  149. package/tests/commands/emails/receiving/attachments.test.ts +0 -168
  150. package/tests/commands/emails/receiving/get.test.ts +0 -140
  151. package/tests/commands/emails/receiving/list.test.ts +0 -181
  152. package/tests/commands/emails/send.test.ts +0 -309
  153. package/tests/commands/segments/create.test.ts +0 -163
  154. package/tests/commands/segments/delete.test.ts +0 -182
  155. package/tests/commands/segments/get.test.ts +0 -137
  156. package/tests/commands/segments/list.test.ts +0 -173
  157. package/tests/commands/teams/list.test.ts +0 -63
  158. package/tests/commands/teams/remove.test.ts +0 -103
  159. package/tests/commands/teams/switch.test.ts +0 -96
  160. package/tests/commands/topics/create.test.ts +0 -191
  161. package/tests/commands/topics/delete.test.ts +0 -156
  162. package/tests/commands/topics/get.test.ts +0 -125
  163. package/tests/commands/topics/list.test.ts +0 -124
  164. package/tests/commands/topics/update.test.ts +0 -177
  165. package/tests/commands/webhooks/create.test.ts +0 -224
  166. package/tests/commands/webhooks/delete.test.ts +0 -156
  167. package/tests/commands/webhooks/get.test.ts +0 -125
  168. package/tests/commands/webhooks/list.test.ts +0 -177
  169. package/tests/commands/webhooks/update.test.ts +0 -206
  170. package/tests/commands/whoami.test.ts +0 -99
  171. package/tests/helpers.ts +0 -93
  172. package/tests/lib/client.test.ts +0 -71
  173. package/tests/lib/config.test.ts +0 -445
  174. package/tests/lib/files.test.ts +0 -65
  175. package/tests/lib/help-text.test.ts +0 -97
  176. package/tests/lib/output.test.ts +0 -127
  177. package/tests/lib/prompts.test.ts +0 -178
  178. package/tests/lib/spinner.test.ts +0 -146
  179. package/tests/lib/table.test.ts +0 -63
  180. package/tests/lib/tty.test.ts +0 -85
  181. package/tests/lib/update-check.test.ts +0 -169
  182. package/tsconfig.json +0 -14
@@ -1,445 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
2
- import { mkdirSync, readFileSync, rmSync, statSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import {
6
- getConfigDir,
7
- listTeams,
8
- removeApiKey,
9
- resolveApiKey,
10
- resolveTeamName,
11
- setActiveTeam,
12
- storeApiKey,
13
- validateTeamName,
14
- } from '../../src/lib/config';
15
- import { captureTestEnv } from '../helpers';
16
-
17
- describe('getConfigDir', () => {
18
- const restoreEnv = captureTestEnv();
19
-
20
- afterEach(() => {
21
- restoreEnv();
22
- });
23
-
24
- test('respects XDG_CONFIG_HOME', () => {
25
- process.env.XDG_CONFIG_HOME = '/custom/config';
26
- expect(getConfigDir()).toBe('/custom/config/resend');
27
- });
28
-
29
- test('falls back to ~/.config/resend on non-Windows', () => {
30
- delete process.env.XDG_CONFIG_HOME;
31
- const dir = getConfigDir();
32
- expect(dir).toMatch(/\.config\/resend$/);
33
- });
34
- });
35
-
36
- describe('resolveApiKey', () => {
37
- const restoreEnv = captureTestEnv();
38
- let tmpDir: string;
39
-
40
- beforeEach(() => {
41
- tmpDir = join(
42
- tmpdir(),
43
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
44
- );
45
- mkdirSync(tmpDir, { recursive: true });
46
- });
47
-
48
- afterEach(() => {
49
- restoreEnv();
50
- rmSync(tmpDir, { recursive: true, force: true });
51
- });
52
-
53
- test('flag value takes highest priority', () => {
54
- process.env.RESEND_API_KEY = 're_env_key';
55
- const result = resolveApiKey('re_flag_key');
56
- expect(result).toEqual({ key: 're_flag_key', source: 'flag' });
57
- });
58
-
59
- test('env var is second priority', () => {
60
- process.env.RESEND_API_KEY = 're_env_key';
61
- const result = resolveApiKey();
62
- expect(result).toEqual({ key: 're_env_key', source: 'env' });
63
- });
64
-
65
- test('config file is third priority', () => {
66
- delete process.env.RESEND_API_KEY;
67
- process.env.XDG_CONFIG_HOME = tmpDir;
68
- const configDir = join(tmpDir, 'resend');
69
- mkdirSync(configDir, { recursive: true });
70
- Bun.write(
71
- join(configDir, 'credentials.json'),
72
- JSON.stringify({
73
- active_team: 'default',
74
- teams: { default: { api_key: 're_config_key' } },
75
- }),
76
- );
77
-
78
- const result = resolveApiKey();
79
- expect(result).toEqual({
80
- key: 're_config_key',
81
- source: 'config',
82
- team: 'default',
83
- });
84
- });
85
-
86
- test('reads legacy format (api_key at root)', () => {
87
- delete process.env.RESEND_API_KEY;
88
- process.env.XDG_CONFIG_HOME = tmpDir;
89
- const configDir = join(tmpDir, 'resend');
90
- mkdirSync(configDir, { recursive: true });
91
- Bun.write(
92
- join(configDir, 'credentials.json'),
93
- JSON.stringify({ api_key: 're_legacy_key' }),
94
- );
95
-
96
- const result = resolveApiKey();
97
- expect(result).toEqual({
98
- key: 're_legacy_key',
99
- source: 'config',
100
- team: 'default',
101
- });
102
- });
103
-
104
- test('resolves specific team from config', () => {
105
- delete process.env.RESEND_API_KEY;
106
- process.env.XDG_CONFIG_HOME = tmpDir;
107
- const configDir = join(tmpDir, 'resend');
108
- mkdirSync(configDir, { recursive: true });
109
- Bun.write(
110
- join(configDir, 'credentials.json'),
111
- JSON.stringify({
112
- active_team: 'default',
113
- teams: {
114
- default: { api_key: 're_default' },
115
- staging: { api_key: 're_staging' },
116
- },
117
- }),
118
- );
119
-
120
- const result = resolveApiKey(undefined, 'staging');
121
- expect(result).toEqual({
122
- key: 're_staging',
123
- source: 'config',
124
- team: 'staging',
125
- });
126
- });
127
-
128
- test('returns null when no key found', () => {
129
- delete process.env.RESEND_API_KEY;
130
- process.env.XDG_CONFIG_HOME = tmpDir;
131
- const result = resolveApiKey();
132
- expect(result).toBeNull();
133
- });
134
-
135
- test('returns null on malformed config JSON', () => {
136
- delete process.env.RESEND_API_KEY;
137
- process.env.XDG_CONFIG_HOME = tmpDir;
138
- const configDir = join(tmpDir, 'resend');
139
- mkdirSync(configDir, { recursive: true });
140
- Bun.write(join(configDir, 'credentials.json'), 'not json');
141
-
142
- const result = resolveApiKey();
143
- expect(result).toBeNull();
144
- });
145
-
146
- test('returns null when team does not exist in config', () => {
147
- delete process.env.RESEND_API_KEY;
148
- process.env.XDG_CONFIG_HOME = tmpDir;
149
- const configDir = join(tmpDir, 'resend');
150
- mkdirSync(configDir, { recursive: true });
151
- Bun.write(
152
- join(configDir, 'credentials.json'),
153
- JSON.stringify({
154
- active_team: 'default',
155
- teams: { default: { api_key: 're_default' } },
156
- }),
157
- );
158
-
159
- const result = resolveApiKey(undefined, 'nonexistent');
160
- expect(result).toBeNull();
161
- });
162
- });
163
-
164
- describe('resolveTeamName', () => {
165
- const restoreEnv = captureTestEnv();
166
- let tmpDir: string;
167
-
168
- beforeEach(() => {
169
- tmpDir = join(
170
- tmpdir(),
171
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
172
- );
173
- mkdirSync(tmpDir, { recursive: true });
174
- process.env.XDG_CONFIG_HOME = tmpDir;
175
- });
176
-
177
- afterEach(() => {
178
- restoreEnv();
179
- rmSync(tmpDir, { recursive: true, force: true });
180
- });
181
-
182
- test('flag value takes highest priority', () => {
183
- process.env.RESEND_TEAM = 'env_team';
184
- expect(resolveTeamName('flag_team')).toBe('flag_team');
185
- });
186
-
187
- test('env var is second priority', () => {
188
- process.env.RESEND_TEAM = 'env_team';
189
- expect(resolveTeamName()).toBe('env_team');
190
- });
191
-
192
- test('active_team from config is third priority', () => {
193
- delete process.env.RESEND_TEAM;
194
- const configDir = join(tmpDir, 'resend');
195
- mkdirSync(configDir, { recursive: true });
196
- Bun.write(
197
- join(configDir, 'credentials.json'),
198
- JSON.stringify({
199
- active_team: 'production',
200
- teams: { production: { api_key: 're_xxx' } },
201
- }),
202
- );
203
-
204
- expect(resolveTeamName()).toBe('production');
205
- });
206
-
207
- test('defaults to "default" when nothing configured', () => {
208
- delete process.env.RESEND_TEAM;
209
- expect(resolveTeamName()).toBe('default');
210
- });
211
- });
212
-
213
- describe('storeApiKey', () => {
214
- const restoreEnv = captureTestEnv();
215
- let tmpDir: string;
216
-
217
- beforeEach(() => {
218
- tmpDir = join(
219
- tmpdir(),
220
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
221
- );
222
- process.env.XDG_CONFIG_HOME = tmpDir;
223
- });
224
-
225
- afterEach(() => {
226
- restoreEnv();
227
- rmSync(tmpDir, { recursive: true, force: true });
228
- });
229
-
230
- test('writes credentials.json with team structure', () => {
231
- const configPath = storeApiKey('re_test_key_123');
232
- expect(configPath).toContain('credentials.json');
233
-
234
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
235
- expect(data.active_team).toBe('default');
236
- expect(data.teams.default.api_key).toBe('re_test_key_123');
237
- });
238
-
239
- test('stores key under specific team name', () => {
240
- const configPath = storeApiKey('re_staging_key', 'staging');
241
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
242
- expect(data.teams.staging.api_key).toBe('re_staging_key');
243
- });
244
-
245
- test('preserves existing teams when adding new one', () => {
246
- storeApiKey('re_default_key');
247
- storeApiKey('re_staging_key', 'staging');
248
-
249
- const configPath = join(tmpDir, 'resend', 'credentials.json');
250
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
251
- expect(data.teams.default.api_key).toBe('re_default_key');
252
- expect(data.teams.staging.api_key).toBe('re_staging_key');
253
- });
254
-
255
- test('creates config directory if it does not exist', () => {
256
- storeApiKey('re_test_key');
257
- const configDir = join(tmpDir, 'resend');
258
- const stat = statSync(configDir);
259
- expect(stat.isDirectory()).toBe(true);
260
- });
261
-
262
- test('sets file permissions to 0600', () => {
263
- const configPath = storeApiKey('re_test_key');
264
- const stat = statSync(configPath);
265
- const mode = stat.mode & 0o777;
266
- expect(mode).toBe(0o600);
267
- });
268
-
269
- test('overwrites existing team key', () => {
270
- storeApiKey('re_first_key');
271
- storeApiKey('re_second_key');
272
-
273
- const configPath = join(tmpDir, 'resend', 'credentials.json');
274
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
275
- expect(data.teams.default.api_key).toBe('re_second_key');
276
- });
277
-
278
- test('sets first team as active', () => {
279
- storeApiKey('re_first_key', 'myteam');
280
-
281
- const configPath = join(tmpDir, 'resend', 'credentials.json');
282
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
283
- expect(data.active_team).toBe('myteam');
284
- });
285
- });
286
-
287
- describe('listTeams', () => {
288
- const restoreEnv = captureTestEnv();
289
- let tmpDir: string;
290
-
291
- beforeEach(() => {
292
- tmpDir = join(
293
- tmpdir(),
294
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
295
- );
296
- process.env.XDG_CONFIG_HOME = tmpDir;
297
- });
298
-
299
- afterEach(() => {
300
- restoreEnv();
301
- rmSync(tmpDir, { recursive: true, force: true });
302
- });
303
-
304
- test('returns empty array when no config', () => {
305
- expect(listTeams()).toEqual([]);
306
- });
307
-
308
- test('returns teams with active flag', () => {
309
- storeApiKey('re_default', 'default');
310
- storeApiKey('re_staging', 'staging');
311
-
312
- const teams = listTeams();
313
- expect(teams).toEqual([
314
- { name: 'default', active: true },
315
- { name: 'staging', active: false },
316
- ]);
317
- });
318
- });
319
-
320
- describe('setActiveTeam', () => {
321
- const restoreEnv = captureTestEnv();
322
- let tmpDir: string;
323
-
324
- beforeEach(() => {
325
- tmpDir = join(
326
- tmpdir(),
327
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
328
- );
329
- process.env.XDG_CONFIG_HOME = tmpDir;
330
- });
331
-
332
- afterEach(() => {
333
- restoreEnv();
334
- rmSync(tmpDir, { recursive: true, force: true });
335
- });
336
-
337
- test('switches active team', () => {
338
- storeApiKey('re_default', 'default');
339
- storeApiKey('re_staging', 'staging');
340
-
341
- setActiveTeam('staging');
342
-
343
- const configPath = join(tmpDir, 'resend', 'credentials.json');
344
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
345
- expect(data.active_team).toBe('staging');
346
- });
347
-
348
- test('throws when team does not exist', () => {
349
- storeApiKey('re_default');
350
- expect(() => setActiveTeam('nonexistent')).toThrow('not found');
351
- });
352
-
353
- test('throws when no credentials file', () => {
354
- expect(() => setActiveTeam('any')).toThrow('No credentials file');
355
- });
356
- });
357
-
358
- describe('removeApiKey', () => {
359
- const restoreEnv = captureTestEnv();
360
- let tmpDir: string;
361
-
362
- beforeEach(() => {
363
- tmpDir = join(
364
- tmpdir(),
365
- `resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
366
- );
367
- process.env.XDG_CONFIG_HOME = tmpDir;
368
- });
369
-
370
- afterEach(() => {
371
- restoreEnv();
372
- rmSync(tmpDir, { recursive: true, force: true });
373
- });
374
-
375
- test('removes a team entry', () => {
376
- storeApiKey('re_default', 'default');
377
- storeApiKey('re_staging', 'staging');
378
-
379
- removeApiKey('staging');
380
-
381
- const teams = listTeams();
382
- expect(teams).toEqual([{ name: 'default', active: true }]);
383
- });
384
-
385
- test('adjusts active_team when active is removed', () => {
386
- storeApiKey('re_default', 'default');
387
- storeApiKey('re_staging', 'staging');
388
- setActiveTeam('staging');
389
-
390
- removeApiKey('staging');
391
-
392
- const configPath = join(tmpDir, 'resend', 'credentials.json');
393
- const data = JSON.parse(readFileSync(configPath, 'utf-8'));
394
- expect(data.active_team).toBe('default');
395
- });
396
-
397
- test('deletes file when last team removed', () => {
398
- storeApiKey('re_only', 'only');
399
-
400
- removeApiKey('only');
401
-
402
- const { existsSync } = require('node:fs');
403
- const configPath = join(tmpDir, 'resend', 'credentials.json');
404
- expect(existsSync(configPath)).toBe(false);
405
- });
406
-
407
- test('throws when team does not exist', () => {
408
- storeApiKey('re_default');
409
- expect(() => removeApiKey('nonexistent')).toThrow('not found');
410
- });
411
-
412
- test('throws when no credentials file', () => {
413
- expect(() => removeApiKey('any')).toThrow('No credentials file');
414
- });
415
- });
416
-
417
- describe('validateTeamName', () => {
418
- test('accepts valid names', () => {
419
- expect(validateTeamName('default')).toBeUndefined();
420
- expect(validateTeamName('my-team')).toBeUndefined();
421
- expect(validateTeamName('team_1')).toBeUndefined();
422
- expect(validateTeamName('prod-2024')).toBeUndefined();
423
- expect(validateTeamName('Production')).toBeUndefined();
424
- expect(validateTeamName('MyTeam')).toBeUndefined();
425
- });
426
-
427
- test('rejects spaces and special characters', () => {
428
- expect(validateTeamName('my team')).toContain('letters');
429
- expect(validateTeamName('team@org')).toContain('letters');
430
- });
431
-
432
- test('rejects empty name', () => {
433
- expect(validateTeamName('')).toContain('empty');
434
- });
435
-
436
- test('rejects names longer than 64 characters', () => {
437
- const longName = 'a'.repeat(65);
438
- expect(validateTeamName(longName)).toContain('64');
439
- });
440
-
441
- test('accepts name exactly 64 characters', () => {
442
- const maxName = 'a'.repeat(64);
443
- expect(validateTeamName(maxName)).toBeUndefined();
444
- });
445
- });
@@ -1,65 +0,0 @@
1
- import { afterEach, describe, expect, spyOn, test } from 'bun:test';
2
- import { unlinkSync, writeFileSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { expectExit1, mockExitThrow } from '../helpers';
5
-
6
- const globalOpts = { json: false, apiKey: undefined };
7
- const jsonOpts = { json: true, apiKey: undefined };
8
-
9
- describe('readFile', () => {
10
- const tmpFile = join(import.meta.dir, 'tmp-test.txt');
11
- let errorSpy: ReturnType<typeof spyOn> | undefined;
12
- let exitSpy: ReturnType<typeof spyOn> | undefined;
13
-
14
- afterEach(() => {
15
- errorSpy?.mockRestore();
16
- errorSpy = undefined;
17
- exitSpy?.mockRestore();
18
- exitSpy = undefined;
19
- try {
20
- unlinkSync(tmpFile);
21
- } catch {
22
- /* already removed */
23
- }
24
- });
25
-
26
- test('reads file content and returns it as a string', () => {
27
- writeFileSync(tmpFile, '<h1>Hello</h1>', 'utf-8');
28
- const { readFile } = require('../../src/lib/files');
29
- const content = readFile(tmpFile, globalOpts);
30
- expect(content).toBe('<h1>Hello</h1>');
31
- });
32
-
33
- test('reads JSON file content and returns it as a string', () => {
34
- writeFileSync(tmpFile, '[{"id":1}]', 'utf-8');
35
- const { readFile } = require('../../src/lib/files');
36
- const content = readFile(tmpFile, globalOpts);
37
- expect(content).toBe('[{"id":1}]');
38
- });
39
-
40
- test('exits with file_read_error when file does not exist', async () => {
41
- errorSpy = spyOn(console, 'error').mockImplementation(() => {});
42
- exitSpy = mockExitThrow();
43
-
44
- const { readFile } = require('../../src/lib/files');
45
- await expectExit1(async () =>
46
- readFile('/nonexistent/path/data.txt', globalOpts),
47
- );
48
-
49
- const output = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
50
- expect(output).toContain('Failed to read file:');
51
- });
52
-
53
- test('outputs JSON error with file_read_error code when json option is true', async () => {
54
- errorSpy = spyOn(console, 'error').mockImplementation(() => {});
55
- exitSpy = mockExitThrow();
56
-
57
- const { readFile } = require('../../src/lib/files');
58
- await expectExit1(async () => readFile('/nonexistent/file.txt', jsonOpts));
59
-
60
- const raw = errorSpy?.mock.calls.map((c) => c[0]).join(' ');
61
- const parsed = JSON.parse(raw);
62
- expect(parsed.error.code).toBe('file_read_error');
63
- expect(parsed.error.message).toContain('Failed to read file:');
64
- });
65
- });
@@ -1,97 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { buildHelpText } from '../../src/lib/help-text';
3
-
4
- describe('buildHelpText', () => {
5
- it('full leaf command — all options, setup: false', () => {
6
- const result = buildHelpText({
7
- context: 'Some context line\n\nNon-interactive: --required-flag <value>',
8
- output: ' {"id":"em_123"}',
9
- errorCodes: ['auth_error', 'send_error'],
10
- examples: [
11
- 'resend emails send --to user@example.com --subject Hi --text Hello',
12
- ],
13
- setup: false,
14
- });
15
-
16
- expect(result).toBe(
17
- '\n' +
18
- 'Some context line\n\nNon-interactive: --required-flag <value>' +
19
- '\n\n' +
20
- 'Global options:\n' +
21
- ' --api-key <key> API key (or set RESEND_API_KEY env var)\n' +
22
- ' --team <name> Team profile to use (overrides RESEND_TEAM)\n' +
23
- ' --json Force JSON output (also auto-enabled when stdout is piped)\n' +
24
- ' -q, --quiet Suppress spinners and status output (implies --json)' +
25
- '\n\n' +
26
- 'Output (--json or piped):\n' +
27
- ' {"id":"em_123"}' +
28
- '\n\n' +
29
- 'Errors (exit code 1):\n' +
30
- ' {"error":{"message":"<message>","code":"<code>"}}\n' +
31
- ' Codes: auth_error | send_error' +
32
- '\n\n' +
33
- 'Examples:\n' +
34
- ' $ resend emails send --to user@example.com --subject Hi --text Hello',
35
- );
36
- });
37
-
38
- it('setup variant — no --api-key line, short --json form', () => {
39
- const result = buildHelpText({
40
- context: 'Setup context',
41
- output: ' {"configured":true}',
42
- errorCodes: ['write_error'],
43
- examples: ['resend setup cursor'],
44
- setup: true,
45
- });
46
-
47
- expect(result).not.toContain('--api-key');
48
- expect(result).toContain('--json Force JSON output');
49
- expect(result).not.toContain('--json Force JSON output');
50
- expect(result).toContain('Global options:');
51
- });
52
-
53
- it('index command — no output, no errorCodes', () => {
54
- const result = buildHelpText({
55
- context: 'Manage emails.',
56
- examples: ['resend emails send', 'resend emails receiving list'],
57
- });
58
-
59
- expect(result).not.toContain('Output (--json or piped):');
60
- expect(result).not.toContain('Errors (exit code 1):');
61
- expect(result).toContain('Global options:');
62
- expect(result).toContain('Examples:');
63
- expect(result).toContain(' $ resend emails send');
64
- expect(result).toContain(' $ resend emails receiving list');
65
- });
66
-
67
- it('no context — string starts with newline then Global options header directly', () => {
68
- const result = buildHelpText({
69
- output: ' {"id":"dm_abc"}',
70
- errorCodes: ['auth_error'],
71
- examples: ['resend domains list'],
72
- });
73
-
74
- expect(result.startsWith('\nGlobal options:')).toBe(true);
75
- });
76
-
77
- it('multi-line output — verbatim after the Output header', () => {
78
- const multiLineOutput =
79
- ' {"id":"em_123"}\n // or with all fields:\n {"id":"em_456","to":["a@b.com"]}';
80
- const result = buildHelpText({
81
- output: multiLineOutput,
82
- errorCodes: ['auth_error'],
83
- examples: ['resend emails send --to a@b.com --subject Hi --text Hi'],
84
- });
85
-
86
- expect(result).toContain(`Output (--json or piped):\n${multiLineOutput}`);
87
- });
88
-
89
- it('error codes join — uses " | " separator', () => {
90
- const result = buildHelpText({
91
- errorCodes: ['auth_error', 'list_error', 'fetch_error'],
92
- examples: ['resend domains list'],
93
- });
94
-
95
- expect(result).toContain('Codes: auth_error | list_error | fetch_error');
96
- });
97
- });