resend-cli 1.0.3 → 1.2.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.
- package/.claude/settings.local.json +5 -0
- package/.claude/worktrees/emails-list/.claude/settings.local.json +5 -0
- package/.claude/worktrees/emails-list/.github/scripts/pr-title-check.js +34 -0
- package/.claude/worktrees/emails-list/.github/workflows/ci.yml +32 -0
- package/.claude/worktrees/emails-list/.github/workflows/pr-title-check.yml +13 -0
- package/.claude/worktrees/emails-list/.github/workflows/release.yml +93 -0
- package/.claude/worktrees/emails-list/CHANGELOG.md +31 -0
- package/.claude/worktrees/emails-list/LICENSE +21 -0
- package/.claude/worktrees/emails-list/README.md +424 -0
- package/.claude/worktrees/emails-list/biome.json +36 -0
- package/.claude/worktrees/emails-list/bun.lock +76 -0
- package/.claude/worktrees/emails-list/bunfig.toml +2 -0
- package/.claude/worktrees/emails-list/install.ps1 +140 -0
- package/.claude/worktrees/emails-list/install.sh +301 -0
- package/.claude/worktrees/emails-list/package.json +43 -0
- package/.claude/worktrees/emails-list/renovate.json +6 -0
- package/.claude/worktrees/emails-list/src/cli.ts +74 -0
- package/.claude/worktrees/emails-list/src/commands/api-keys/create.ts +114 -0
- package/.claude/worktrees/emails-list/src/commands/api-keys/delete.ts +47 -0
- package/.claude/worktrees/emails-list/src/commands/api-keys/index.ts +26 -0
- package/.claude/worktrees/emails-list/src/commands/api-keys/list.ts +35 -0
- package/.claude/worktrees/emails-list/src/commands/api-keys/utils.ts +8 -0
- package/.claude/worktrees/emails-list/src/commands/auth/index.ts +20 -0
- package/.claude/worktrees/emails-list/src/commands/auth/login.ts +207 -0
- package/.claude/worktrees/emails-list/src/commands/auth/logout.ts +105 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/create.ts +196 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/delete.ts +46 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/get.ts +59 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/index.ts +43 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/list.ts +60 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/send.ts +56 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/update.ts +95 -0
- package/.claude/worktrees/emails-list/src/commands/broadcasts/utils.ts +35 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/create.ts +118 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/delete.ts +48 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/get.ts +46 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/index.ts +48 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/list.ts +68 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/update.ts +88 -0
- package/.claude/worktrees/emails-list/src/commands/contact-properties/utils.ts +17 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/add-segment.ts +78 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/create.ts +122 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/delete.ts +49 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/get.ts +53 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/index.ts +58 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/list.ts +57 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/remove-segment.ts +48 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/segments.ts +39 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/topics.ts +45 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/update-topics.ts +90 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/update.ts +77 -0
- package/.claude/worktrees/emails-list/src/commands/contacts/utils.ts +119 -0
- package/.claude/worktrees/emails-list/src/commands/doctor.ts +298 -0
- package/.claude/worktrees/emails-list/src/commands/domains/create.ts +83 -0
- package/.claude/worktrees/emails-list/src/commands/domains/delete.ts +42 -0
- package/.claude/worktrees/emails-list/src/commands/domains/get.ts +47 -0
- package/.claude/worktrees/emails-list/src/commands/domains/index.ts +35 -0
- package/.claude/worktrees/emails-list/src/commands/domains/list.ts +53 -0
- package/.claude/worktrees/emails-list/src/commands/domains/update.ts +75 -0
- package/.claude/worktrees/emails-list/src/commands/domains/utils.ts +44 -0
- package/.claude/worktrees/emails-list/src/commands/domains/verify.ts +38 -0
- package/.claude/worktrees/emails-list/src/commands/emails/batch.ts +140 -0
- package/.claude/worktrees/emails-list/src/commands/emails/index.ts +28 -0
- package/.claude/worktrees/emails-list/src/commands/emails/list.ts +73 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachment.ts +55 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/attachments.ts +68 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/get.ts +58 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/index.ts +28 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/list.ts +59 -0
- package/.claude/worktrees/emails-list/src/commands/emails/receiving/utils.ts +38 -0
- package/.claude/worktrees/emails-list/src/commands/emails/send.ts +189 -0
- package/.claude/worktrees/emails-list/src/commands/open.ts +24 -0
- package/.claude/worktrees/emails-list/src/commands/segments/create.ts +50 -0
- package/.claude/worktrees/emails-list/src/commands/segments/delete.ts +47 -0
- package/.claude/worktrees/emails-list/src/commands/segments/get.ts +38 -0
- package/.claude/worktrees/emails-list/src/commands/segments/index.ts +36 -0
- package/.claude/worktrees/emails-list/src/commands/segments/list.ts +58 -0
- package/.claude/worktrees/emails-list/src/commands/segments/utils.ts +7 -0
- package/.claude/worktrees/emails-list/src/commands/teams/index.ts +10 -0
- package/.claude/worktrees/emails-list/src/commands/teams/list.ts +35 -0
- package/.claude/worktrees/emails-list/src/commands/teams/remove.ts +83 -0
- package/.claude/worktrees/emails-list/src/commands/teams/switch.ts +73 -0
- package/.claude/worktrees/emails-list/src/commands/topics/create.ts +73 -0
- package/.claude/worktrees/emails-list/src/commands/topics/delete.ts +47 -0
- package/.claude/worktrees/emails-list/src/commands/topics/get.ts +42 -0
- package/.claude/worktrees/emails-list/src/commands/topics/index.ts +42 -0
- package/.claude/worktrees/emails-list/src/commands/topics/list.ts +34 -0
- package/.claude/worktrees/emails-list/src/commands/topics/update.ts +59 -0
- package/.claude/worktrees/emails-list/src/commands/topics/utils.ts +16 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/create.ts +128 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/delete.ts +49 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/get.ts +42 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/index.ts +44 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/list.ts +55 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/update.ts +83 -0
- package/.claude/worktrees/emails-list/src/commands/webhooks/utils.ts +36 -0
- package/.claude/worktrees/emails-list/src/commands/whoami.ts +71 -0
- package/.claude/worktrees/emails-list/src/lib/actions.ts +157 -0
- package/.claude/worktrees/emails-list/src/lib/client.ts +34 -0
- package/.claude/worktrees/emails-list/src/lib/config.ts +211 -0
- package/.claude/worktrees/emails-list/src/lib/files.ts +15 -0
- package/.claude/worktrees/emails-list/src/lib/help-text.ts +38 -0
- package/.claude/worktrees/emails-list/src/lib/output.ts +54 -0
- package/.claude/worktrees/emails-list/src/lib/pagination.ts +36 -0
- package/.claude/worktrees/emails-list/src/lib/prompts.ts +149 -0
- package/.claude/worktrees/emails-list/src/lib/spinner.ts +93 -0
- package/.claude/worktrees/emails-list/src/lib/table.ts +57 -0
- package/.claude/worktrees/emails-list/src/lib/tty.ts +28 -0
- package/.claude/worktrees/emails-list/src/lib/version.ts +4 -0
- package/.claude/worktrees/emails-list/tests/commands/api-keys/create.test.ts +195 -0
- package/.claude/worktrees/emails-list/tests/commands/api-keys/delete.test.ts +156 -0
- package/.claude/worktrees/emails-list/tests/commands/api-keys/list.test.ts +133 -0
- package/.claude/worktrees/emails-list/tests/commands/auth/login.test.ts +119 -0
- package/.claude/worktrees/emails-list/tests/commands/auth/logout.test.ts +146 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/create.test.ts +447 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/delete.test.ts +182 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/get.test.ts +146 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/list.test.ts +196 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/send.test.ts +161 -0
- package/.claude/worktrees/emails-list/tests/commands/broadcasts/update.test.ts +283 -0
- package/.claude/worktrees/emails-list/tests/commands/contact-properties/create.test.ts +250 -0
- package/.claude/worktrees/emails-list/tests/commands/contact-properties/delete.test.ts +183 -0
- package/.claude/worktrees/emails-list/tests/commands/contact-properties/get.test.ts +144 -0
- package/.claude/worktrees/emails-list/tests/commands/contact-properties/list.test.ts +180 -0
- package/.claude/worktrees/emails-list/tests/commands/contact-properties/update.test.ts +216 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/add-segment.test.ts +188 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/create.test.ts +270 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/delete.test.ts +192 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/get.test.ts +148 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/list.test.ts +175 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/remove-segment.test.ts +166 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/segments.test.ts +167 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/topics.test.ts +163 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/update-topics.test.ts +247 -0
- package/.claude/worktrees/emails-list/tests/commands/contacts/update.test.ts +205 -0
- package/.claude/worktrees/emails-list/tests/commands/doctor.test.ts +165 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/create.test.ts +192 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/delete.test.ts +156 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/get.test.ts +137 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/list.test.ts +164 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/update.test.ts +223 -0
- package/.claude/worktrees/emails-list/tests/commands/domains/verify.test.ts +117 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/batch.test.ts +313 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/list.test.ts +196 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachment.test.ts +140 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/receiving/attachments.test.ts +168 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/receiving/get.test.ts +140 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/receiving/list.test.ts +181 -0
- package/.claude/worktrees/emails-list/tests/commands/emails/send.test.ts +309 -0
- package/.claude/worktrees/emails-list/tests/commands/segments/create.test.ts +163 -0
- package/.claude/worktrees/emails-list/tests/commands/segments/delete.test.ts +182 -0
- package/.claude/worktrees/emails-list/tests/commands/segments/get.test.ts +137 -0
- package/.claude/worktrees/emails-list/tests/commands/segments/list.test.ts +173 -0
- package/.claude/worktrees/emails-list/tests/commands/teams/list.test.ts +63 -0
- package/.claude/worktrees/emails-list/tests/commands/teams/remove.test.ts +103 -0
- package/.claude/worktrees/emails-list/tests/commands/teams/switch.test.ts +96 -0
- package/.claude/worktrees/emails-list/tests/commands/topics/create.test.ts +191 -0
- package/.claude/worktrees/emails-list/tests/commands/topics/delete.test.ts +156 -0
- package/.claude/worktrees/emails-list/tests/commands/topics/get.test.ts +125 -0
- package/.claude/worktrees/emails-list/tests/commands/topics/list.test.ts +124 -0
- package/.claude/worktrees/emails-list/tests/commands/topics/update.test.ts +177 -0
- package/.claude/worktrees/emails-list/tests/commands/webhooks/create.test.ts +224 -0
- package/.claude/worktrees/emails-list/tests/commands/webhooks/delete.test.ts +156 -0
- package/.claude/worktrees/emails-list/tests/commands/webhooks/get.test.ts +125 -0
- package/.claude/worktrees/emails-list/tests/commands/webhooks/list.test.ts +177 -0
- package/.claude/worktrees/emails-list/tests/commands/webhooks/update.test.ts +206 -0
- package/.claude/worktrees/emails-list/tests/commands/whoami.test.ts +99 -0
- package/.claude/worktrees/emails-list/tests/helpers.ts +93 -0
- package/.claude/worktrees/emails-list/tests/lib/client.test.ts +71 -0
- package/.claude/worktrees/emails-list/tests/lib/config.test.ts +414 -0
- package/.claude/worktrees/emails-list/tests/lib/files.test.ts +65 -0
- package/.claude/worktrees/emails-list/tests/lib/help-text.test.ts +97 -0
- package/.claude/worktrees/emails-list/tests/lib/output.test.ts +127 -0
- package/.claude/worktrees/emails-list/tests/lib/prompts.test.ts +178 -0
- package/.claude/worktrees/emails-list/tests/lib/spinner.test.ts +146 -0
- package/.claude/worktrees/emails-list/tests/lib/table.test.ts +63 -0
- package/.claude/worktrees/emails-list/tests/lib/tty.test.ts +85 -0
- package/.claude/worktrees/emails-list/tsconfig.json +14 -0
- package/.github/scripts/pr-title-check.js +34 -0
- package/.github/workflows/ci.yml +32 -0
- package/.github/workflows/pr-title-check.yml +13 -0
- package/.github/workflows/release.yml +93 -0
- package/.github/workflows/test-build-windows.yml +44 -0
- package/.github/workflows/test-install-windows.yml +48 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -21
- package/README.md +424 -19
- package/biome.json +36 -0
- package/bun.lock +76 -0
- package/bunfig.toml +2 -0
- package/docs/agent-dx-gaps.md +167 -0
- package/docs/missing-commands.md +58 -0
- package/docs/production-readiness.md +99 -0
- package/docs/secure-key-storage.md +174 -0
- package/install.ps1 +141 -0
- package/install.sh +301 -0
- package/package.json +43 -22
- package/renovate.json +4 -0
- package/src/cli.ts +74 -0
- package/src/commands/api-keys/create.ts +114 -0
- package/src/commands/api-keys/delete.ts +47 -0
- package/src/commands/api-keys/index.ts +26 -0
- package/src/commands/api-keys/list.ts +35 -0
- package/src/commands/api-keys/utils.ts +8 -0
- package/src/commands/auth/index.ts +20 -0
- package/src/commands/auth/login.ts +232 -0
- package/src/commands/auth/logout.ts +105 -0
- package/src/commands/broadcasts/create.ts +196 -0
- package/src/commands/broadcasts/delete.ts +46 -0
- package/src/commands/broadcasts/get.ts +59 -0
- package/src/commands/broadcasts/index.ts +43 -0
- package/src/commands/broadcasts/list.ts +60 -0
- package/src/commands/broadcasts/send.ts +56 -0
- package/src/commands/broadcasts/update.ts +95 -0
- package/src/commands/broadcasts/utils.ts +35 -0
- package/src/commands/contact-properties/create.ts +118 -0
- package/src/commands/contact-properties/delete.ts +48 -0
- package/src/commands/contact-properties/get.ts +46 -0
- package/src/commands/contact-properties/index.ts +48 -0
- package/src/commands/contact-properties/list.ts +68 -0
- package/src/commands/contact-properties/update.ts +88 -0
- package/src/commands/contact-properties/utils.ts +17 -0
- package/src/commands/contacts/add-segment.ts +78 -0
- package/src/commands/contacts/create.ts +122 -0
- package/src/commands/contacts/delete.ts +49 -0
- package/src/commands/contacts/get.ts +53 -0
- package/src/commands/contacts/index.ts +58 -0
- package/src/commands/contacts/list.ts +57 -0
- package/src/commands/contacts/remove-segment.ts +48 -0
- package/src/commands/contacts/segments.ts +39 -0
- package/src/commands/contacts/topics.ts +45 -0
- package/src/commands/contacts/update-topics.ts +90 -0
- package/src/commands/contacts/update.ts +77 -0
- package/src/commands/contacts/utils.ts +119 -0
- package/src/commands/doctor.ts +298 -0
- package/src/commands/domains/create.ts +83 -0
- package/src/commands/domains/delete.ts +42 -0
- package/src/commands/domains/get.ts +47 -0
- package/src/commands/domains/index.ts +35 -0
- package/src/commands/domains/list.ts +53 -0
- package/src/commands/domains/update.ts +75 -0
- package/src/commands/domains/utils.ts +44 -0
- package/src/commands/domains/verify.ts +38 -0
- package/src/commands/emails/batch.ts +140 -0
- package/src/commands/emails/index.ts +24 -0
- package/src/commands/emails/receiving/attachment.ts +55 -0
- package/src/commands/emails/receiving/attachments.ts +68 -0
- package/src/commands/emails/receiving/get.ts +58 -0
- package/src/commands/emails/receiving/index.ts +28 -0
- package/src/commands/emails/receiving/list.ts +59 -0
- package/src/commands/emails/receiving/utils.ts +38 -0
- package/src/commands/emails/send.ts +189 -0
- package/src/commands/open.ts +24 -0
- package/src/commands/segments/create.ts +50 -0
- package/src/commands/segments/delete.ts +47 -0
- package/src/commands/segments/get.ts +38 -0
- package/src/commands/segments/index.ts +36 -0
- package/src/commands/segments/list.ts +58 -0
- package/src/commands/segments/utils.ts +7 -0
- package/src/commands/teams/index.ts +10 -0
- package/src/commands/teams/list.ts +35 -0
- package/src/commands/teams/remove.ts +86 -0
- package/src/commands/teams/switch.ts +76 -0
- package/src/commands/topics/create.ts +73 -0
- package/src/commands/topics/delete.ts +47 -0
- package/src/commands/topics/get.ts +42 -0
- package/src/commands/topics/index.ts +42 -0
- package/src/commands/topics/list.ts +34 -0
- package/src/commands/topics/update.ts +59 -0
- package/src/commands/topics/utils.ts +16 -0
- package/src/commands/webhooks/create.ts +128 -0
- package/src/commands/webhooks/delete.ts +49 -0
- package/src/commands/webhooks/get.ts +42 -0
- package/src/commands/webhooks/index.ts +44 -0
- package/src/commands/webhooks/list.ts +55 -0
- package/src/commands/webhooks/update.ts +83 -0
- package/src/commands/webhooks/utils.ts +36 -0
- package/src/commands/whoami.ts +71 -0
- package/src/lib/actions.ts +157 -0
- package/src/lib/client.ts +34 -0
- package/src/lib/config.ts +218 -0
- package/src/lib/files.ts +15 -0
- package/src/lib/help-text.ts +38 -0
- package/src/lib/output.ts +54 -0
- package/src/lib/pagination.ts +36 -0
- package/src/lib/prompts.ts +149 -0
- package/src/lib/spinner.ts +93 -0
- package/src/lib/table.ts +57 -0
- package/src/lib/tty.ts +28 -0
- package/src/lib/version.ts +4 -0
- package/tests/commands/api-keys/create.test.ts +195 -0
- package/tests/commands/api-keys/delete.test.ts +156 -0
- package/tests/commands/api-keys/list.test.ts +133 -0
- package/tests/commands/auth/login.test.ts +154 -0
- package/tests/commands/auth/logout.test.ts +146 -0
- package/tests/commands/broadcasts/create.test.ts +447 -0
- package/tests/commands/broadcasts/delete.test.ts +182 -0
- package/tests/commands/broadcasts/get.test.ts +146 -0
- package/tests/commands/broadcasts/list.test.ts +196 -0
- package/tests/commands/broadcasts/send.test.ts +161 -0
- package/tests/commands/broadcasts/update.test.ts +283 -0
- package/tests/commands/contact-properties/create.test.ts +250 -0
- package/tests/commands/contact-properties/delete.test.ts +183 -0
- package/tests/commands/contact-properties/get.test.ts +144 -0
- package/tests/commands/contact-properties/list.test.ts +180 -0
- package/tests/commands/contact-properties/update.test.ts +216 -0
- package/tests/commands/contacts/add-segment.test.ts +188 -0
- package/tests/commands/contacts/create.test.ts +270 -0
- package/tests/commands/contacts/delete.test.ts +192 -0
- package/tests/commands/contacts/get.test.ts +148 -0
- package/tests/commands/contacts/list.test.ts +175 -0
- package/tests/commands/contacts/remove-segment.test.ts +166 -0
- package/tests/commands/contacts/segments.test.ts +167 -0
- package/tests/commands/contacts/topics.test.ts +163 -0
- package/tests/commands/contacts/update-topics.test.ts +247 -0
- package/tests/commands/contacts/update.test.ts +205 -0
- package/tests/commands/doctor.test.ts +165 -0
- package/tests/commands/domains/create.test.ts +192 -0
- package/tests/commands/domains/delete.test.ts +156 -0
- package/tests/commands/domains/get.test.ts +137 -0
- package/tests/commands/domains/list.test.ts +164 -0
- package/tests/commands/domains/update.test.ts +223 -0
- package/tests/commands/domains/verify.test.ts +117 -0
- package/tests/commands/emails/batch.test.ts +313 -0
- package/tests/commands/emails/receiving/attachment.test.ts +140 -0
- package/tests/commands/emails/receiving/attachments.test.ts +168 -0
- package/tests/commands/emails/receiving/get.test.ts +140 -0
- package/tests/commands/emails/receiving/list.test.ts +181 -0
- package/tests/commands/emails/send.test.ts +309 -0
- package/tests/commands/segments/create.test.ts +163 -0
- package/tests/commands/segments/delete.test.ts +182 -0
- package/tests/commands/segments/get.test.ts +137 -0
- package/tests/commands/segments/list.test.ts +173 -0
- package/tests/commands/teams/list.test.ts +63 -0
- package/tests/commands/teams/remove.test.ts +103 -0
- package/tests/commands/teams/switch.test.ts +96 -0
- package/tests/commands/topics/create.test.ts +191 -0
- package/tests/commands/topics/delete.test.ts +156 -0
- package/tests/commands/topics/get.test.ts +125 -0
- package/tests/commands/topics/list.test.ts +124 -0
- package/tests/commands/topics/update.test.ts +177 -0
- package/tests/commands/webhooks/create.test.ts +224 -0
- package/tests/commands/webhooks/delete.test.ts +156 -0
- package/tests/commands/webhooks/get.test.ts +125 -0
- package/tests/commands/webhooks/list.test.ts +177 -0
- package/tests/commands/webhooks/update.test.ts +206 -0
- package/tests/commands/whoami.test.ts +99 -0
- package/tests/helpers.ts +93 -0
- package/tests/lib/client.test.ts +71 -0
- package/tests/lib/config.test.ts +447 -0
- package/tests/lib/files.test.ts +65 -0
- package/tests/lib/help-text.test.ts +97 -0
- package/tests/lib/output.test.ts +127 -0
- package/tests/lib/prompts.test.ts +178 -0
- package/tests/lib/spinner.test.ts +146 -0
- package/tests/lib/table.test.ts +63 -0
- package/tests/lib/tty.test.ts +85 -0
- package/tsconfig.json +14 -0
- package/src/index.js +0 -72
- package/src/routes.js +0 -37
- package/src/sections/apikeys.js +0 -99
- package/src/sections/audiences.js +0 -84
- package/src/sections/contacts.js +0 -177
- package/src/sections/domain.js +0 -195
- package/src/sections/email.js +0 -132
|
@@ -0,0 +1,414 @@
|
|
|
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
|
+
removeTeam,
|
|
9
|
+
resolveApiKey,
|
|
10
|
+
resolveTeamName,
|
|
11
|
+
setActiveTeam,
|
|
12
|
+
storeApiKey,
|
|
13
|
+
} from '../../src/lib/config';
|
|
14
|
+
import { captureTestEnv } from '../helpers';
|
|
15
|
+
|
|
16
|
+
describe('getConfigDir', () => {
|
|
17
|
+
const restoreEnv = captureTestEnv();
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
restoreEnv();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('respects XDG_CONFIG_HOME', () => {
|
|
24
|
+
process.env.XDG_CONFIG_HOME = '/custom/config';
|
|
25
|
+
expect(getConfigDir()).toBe('/custom/config/resend');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('falls back to ~/.config/resend on non-Windows', () => {
|
|
29
|
+
delete process.env.XDG_CONFIG_HOME;
|
|
30
|
+
const dir = getConfigDir();
|
|
31
|
+
expect(dir).toMatch(/\.config\/resend$/);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('resolveApiKey', () => {
|
|
36
|
+
const restoreEnv = captureTestEnv();
|
|
37
|
+
let tmpDir: string;
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
tmpDir = join(
|
|
41
|
+
tmpdir(),
|
|
42
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
43
|
+
);
|
|
44
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
restoreEnv();
|
|
49
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('flag value takes highest priority', () => {
|
|
53
|
+
process.env.RESEND_API_KEY = 're_env_key';
|
|
54
|
+
const result = resolveApiKey('re_flag_key');
|
|
55
|
+
expect(result).toEqual({ key: 're_flag_key', source: 'flag' });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('env var is second priority', () => {
|
|
59
|
+
process.env.RESEND_API_KEY = 're_env_key';
|
|
60
|
+
const result = resolveApiKey();
|
|
61
|
+
expect(result).toEqual({ key: 're_env_key', source: 'env' });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('config file is third priority', () => {
|
|
65
|
+
delete process.env.RESEND_API_KEY;
|
|
66
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
67
|
+
const configDir = join(tmpDir, 'resend');
|
|
68
|
+
mkdirSync(configDir, { recursive: true });
|
|
69
|
+
Bun.write(
|
|
70
|
+
join(configDir, 'credentials.json'),
|
|
71
|
+
JSON.stringify({
|
|
72
|
+
active_team: 'default',
|
|
73
|
+
teams: { default: { api_key: 're_config_key' } },
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const result = resolveApiKey();
|
|
78
|
+
expect(result).toEqual({
|
|
79
|
+
key: 're_config_key',
|
|
80
|
+
source: 'config',
|
|
81
|
+
team: 'default',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('reads legacy format (api_key at root)', () => {
|
|
86
|
+
delete process.env.RESEND_API_KEY;
|
|
87
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
88
|
+
const configDir = join(tmpDir, 'resend');
|
|
89
|
+
mkdirSync(configDir, { recursive: true });
|
|
90
|
+
Bun.write(
|
|
91
|
+
join(configDir, 'credentials.json'),
|
|
92
|
+
JSON.stringify({ api_key: 're_legacy_key' }),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const result = resolveApiKey();
|
|
96
|
+
expect(result).toEqual({
|
|
97
|
+
key: 're_legacy_key',
|
|
98
|
+
source: 'config',
|
|
99
|
+
team: 'default',
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('resolves specific team from config', () => {
|
|
104
|
+
delete process.env.RESEND_API_KEY;
|
|
105
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
106
|
+
const configDir = join(tmpDir, 'resend');
|
|
107
|
+
mkdirSync(configDir, { recursive: true });
|
|
108
|
+
Bun.write(
|
|
109
|
+
join(configDir, 'credentials.json'),
|
|
110
|
+
JSON.stringify({
|
|
111
|
+
active_team: 'default',
|
|
112
|
+
teams: {
|
|
113
|
+
default: { api_key: 're_default' },
|
|
114
|
+
staging: { api_key: 're_staging' },
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const result = resolveApiKey(undefined, 'staging');
|
|
120
|
+
expect(result).toEqual({
|
|
121
|
+
key: 're_staging',
|
|
122
|
+
source: 'config',
|
|
123
|
+
team: 'staging',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('returns null when no key found', () => {
|
|
128
|
+
delete process.env.RESEND_API_KEY;
|
|
129
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
130
|
+
const result = resolveApiKey();
|
|
131
|
+
expect(result).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('returns null on malformed config JSON', () => {
|
|
135
|
+
delete process.env.RESEND_API_KEY;
|
|
136
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
137
|
+
const configDir = join(tmpDir, 'resend');
|
|
138
|
+
mkdirSync(configDir, { recursive: true });
|
|
139
|
+
Bun.write(join(configDir, 'credentials.json'), 'not json');
|
|
140
|
+
|
|
141
|
+
const result = resolveApiKey();
|
|
142
|
+
expect(result).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('returns null when team does not exist in config', () => {
|
|
146
|
+
delete process.env.RESEND_API_KEY;
|
|
147
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
148
|
+
const configDir = join(tmpDir, 'resend');
|
|
149
|
+
mkdirSync(configDir, { recursive: true });
|
|
150
|
+
Bun.write(
|
|
151
|
+
join(configDir, 'credentials.json'),
|
|
152
|
+
JSON.stringify({
|
|
153
|
+
active_team: 'default',
|
|
154
|
+
teams: { default: { api_key: 're_default' } },
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const result = resolveApiKey(undefined, 'nonexistent');
|
|
159
|
+
expect(result).toBeNull();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('resolveTeamName', () => {
|
|
164
|
+
const restoreEnv = captureTestEnv();
|
|
165
|
+
let tmpDir: string;
|
|
166
|
+
|
|
167
|
+
beforeEach(() => {
|
|
168
|
+
tmpDir = join(
|
|
169
|
+
tmpdir(),
|
|
170
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
171
|
+
);
|
|
172
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
173
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
afterEach(() => {
|
|
177
|
+
restoreEnv();
|
|
178
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('flag value takes highest priority', () => {
|
|
182
|
+
process.env.RESEND_TEAM = 'env_team';
|
|
183
|
+
expect(resolveTeamName('flag_team')).toBe('flag_team');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('env var is second priority', () => {
|
|
187
|
+
process.env.RESEND_TEAM = 'env_team';
|
|
188
|
+
expect(resolveTeamName()).toBe('env_team');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('active_team from config is third priority', () => {
|
|
192
|
+
delete process.env.RESEND_TEAM;
|
|
193
|
+
const configDir = join(tmpDir, 'resend');
|
|
194
|
+
mkdirSync(configDir, { recursive: true });
|
|
195
|
+
Bun.write(
|
|
196
|
+
join(configDir, 'credentials.json'),
|
|
197
|
+
JSON.stringify({
|
|
198
|
+
active_team: 'production',
|
|
199
|
+
teams: { production: { api_key: 're_xxx' } },
|
|
200
|
+
}),
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
expect(resolveTeamName()).toBe('production');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('defaults to "default" when nothing configured', () => {
|
|
207
|
+
delete process.env.RESEND_TEAM;
|
|
208
|
+
expect(resolveTeamName()).toBe('default');
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('storeApiKey', () => {
|
|
213
|
+
const restoreEnv = captureTestEnv();
|
|
214
|
+
let tmpDir: string;
|
|
215
|
+
|
|
216
|
+
beforeEach(() => {
|
|
217
|
+
tmpDir = join(
|
|
218
|
+
tmpdir(),
|
|
219
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
220
|
+
);
|
|
221
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
afterEach(() => {
|
|
225
|
+
restoreEnv();
|
|
226
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('writes credentials.json with team structure', () => {
|
|
230
|
+
const configPath = storeApiKey('re_test_key_123');
|
|
231
|
+
expect(configPath).toContain('credentials.json');
|
|
232
|
+
|
|
233
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
234
|
+
expect(data.active_team).toBe('default');
|
|
235
|
+
expect(data.teams.default.api_key).toBe('re_test_key_123');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('stores key under specific team name', () => {
|
|
239
|
+
const configPath = storeApiKey('re_staging_key', 'staging');
|
|
240
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
241
|
+
expect(data.teams.staging.api_key).toBe('re_staging_key');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('preserves existing teams when adding new one', () => {
|
|
245
|
+
storeApiKey('re_default_key');
|
|
246
|
+
storeApiKey('re_staging_key', 'staging');
|
|
247
|
+
|
|
248
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
249
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
250
|
+
expect(data.teams.default.api_key).toBe('re_default_key');
|
|
251
|
+
expect(data.teams.staging.api_key).toBe('re_staging_key');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('creates config directory if it does not exist', () => {
|
|
255
|
+
storeApiKey('re_test_key');
|
|
256
|
+
const configDir = join(tmpDir, 'resend');
|
|
257
|
+
const stat = statSync(configDir);
|
|
258
|
+
expect(stat.isDirectory()).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('sets file permissions to 0600', () => {
|
|
262
|
+
const configPath = storeApiKey('re_test_key');
|
|
263
|
+
const stat = statSync(configPath);
|
|
264
|
+
const mode = stat.mode & 0o777;
|
|
265
|
+
expect(mode).toBe(0o600);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('overwrites existing team key', () => {
|
|
269
|
+
storeApiKey('re_first_key');
|
|
270
|
+
storeApiKey('re_second_key');
|
|
271
|
+
|
|
272
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
273
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
274
|
+
expect(data.teams.default.api_key).toBe('re_second_key');
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('sets first team as active', () => {
|
|
278
|
+
storeApiKey('re_first_key', 'myteam');
|
|
279
|
+
|
|
280
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
281
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
282
|
+
expect(data.active_team).toBe('myteam');
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
describe('listTeams', () => {
|
|
287
|
+
const restoreEnv = captureTestEnv();
|
|
288
|
+
let tmpDir: string;
|
|
289
|
+
|
|
290
|
+
beforeEach(() => {
|
|
291
|
+
tmpDir = join(
|
|
292
|
+
tmpdir(),
|
|
293
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
294
|
+
);
|
|
295
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
afterEach(() => {
|
|
299
|
+
restoreEnv();
|
|
300
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('returns empty array when no config', () => {
|
|
304
|
+
expect(listTeams()).toEqual([]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('returns teams with active flag', () => {
|
|
308
|
+
storeApiKey('re_default', 'default');
|
|
309
|
+
storeApiKey('re_staging', 'staging');
|
|
310
|
+
|
|
311
|
+
const teams = listTeams();
|
|
312
|
+
expect(teams).toEqual([
|
|
313
|
+
{ name: 'default', active: true },
|
|
314
|
+
{ name: 'staging', active: false },
|
|
315
|
+
]);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe('setActiveTeam', () => {
|
|
320
|
+
const restoreEnv = captureTestEnv();
|
|
321
|
+
let tmpDir: string;
|
|
322
|
+
|
|
323
|
+
beforeEach(() => {
|
|
324
|
+
tmpDir = join(
|
|
325
|
+
tmpdir(),
|
|
326
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
327
|
+
);
|
|
328
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
afterEach(() => {
|
|
332
|
+
restoreEnv();
|
|
333
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('switches active team', () => {
|
|
337
|
+
storeApiKey('re_default', 'default');
|
|
338
|
+
storeApiKey('re_staging', 'staging');
|
|
339
|
+
|
|
340
|
+
setActiveTeam('staging');
|
|
341
|
+
|
|
342
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
343
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
344
|
+
expect(data.active_team).toBe('staging');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('throws when team does not exist', () => {
|
|
348
|
+
storeApiKey('re_default');
|
|
349
|
+
expect(() => setActiveTeam('nonexistent')).toThrow('not found');
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('throws when no credentials file', () => {
|
|
353
|
+
expect(() => setActiveTeam('any')).toThrow('No credentials file');
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
describe('removeTeam', () => {
|
|
358
|
+
const restoreEnv = captureTestEnv();
|
|
359
|
+
let tmpDir: string;
|
|
360
|
+
|
|
361
|
+
beforeEach(() => {
|
|
362
|
+
tmpDir = join(
|
|
363
|
+
tmpdir(),
|
|
364
|
+
`resend-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
365
|
+
);
|
|
366
|
+
process.env.XDG_CONFIG_HOME = tmpDir;
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
afterEach(() => {
|
|
370
|
+
restoreEnv();
|
|
371
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test('removes a team entry', () => {
|
|
375
|
+
storeApiKey('re_default', 'default');
|
|
376
|
+
storeApiKey('re_staging', 'staging');
|
|
377
|
+
|
|
378
|
+
removeTeam('staging');
|
|
379
|
+
|
|
380
|
+
const teams = listTeams();
|
|
381
|
+
expect(teams).toEqual([{ name: 'default', active: true }]);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('adjusts active_team when active is removed', () => {
|
|
385
|
+
storeApiKey('re_default', 'default');
|
|
386
|
+
storeApiKey('re_staging', 'staging');
|
|
387
|
+
setActiveTeam('staging');
|
|
388
|
+
|
|
389
|
+
removeTeam('staging');
|
|
390
|
+
|
|
391
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
392
|
+
const data = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
393
|
+
expect(data.active_team).toBe('default');
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test('deletes file when last team removed', () => {
|
|
397
|
+
storeApiKey('re_only', 'only');
|
|
398
|
+
|
|
399
|
+
removeTeam('only');
|
|
400
|
+
|
|
401
|
+
const { existsSync } = require('node:fs');
|
|
402
|
+
const configPath = join(tmpDir, 'resend', 'credentials.json');
|
|
403
|
+
expect(existsSync(configPath)).toBe(false);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('throws when team does not exist', () => {
|
|
407
|
+
storeApiKey('re_default');
|
|
408
|
+
expect(() => removeTeam('nonexistent')).toThrow('not found');
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('throws when no credentials file', () => {
|
|
412
|
+
expect(() => removeTeam('any')).toThrow('No credentials file');
|
|
413
|
+
});
|
|
414
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { afterEach, describe, expect, spyOn, test } from 'bun:test';
|
|
2
|
+
import { outputError, outputResult } from '../../src/lib/output';
|
|
3
|
+
|
|
4
|
+
describe('outputResult', () => {
|
|
5
|
+
let logSpy: ReturnType<typeof spyOn>;
|
|
6
|
+
const originalIsTTY = process.stdout.isTTY;
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
logSpy?.mockRestore();
|
|
10
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
11
|
+
value: originalIsTTY,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('outputs JSON when json option is true', () => {
|
|
17
|
+
logSpy = spyOn(console, 'log').mockImplementation(() => {});
|
|
18
|
+
outputResult({ id: '123' }, { json: true });
|
|
19
|
+
expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('outputs JSON when stdout is not TTY', () => {
|
|
23
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
24
|
+
value: undefined,
|
|
25
|
+
writable: true,
|
|
26
|
+
});
|
|
27
|
+
logSpy = spyOn(console, 'log').mockImplementation(() => {});
|
|
28
|
+
outputResult({ id: '123' });
|
|
29
|
+
expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('outputs string directly for human-readable mode', () => {
|
|
33
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
34
|
+
value: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
});
|
|
37
|
+
logSpy = spyOn(console, 'log').mockImplementation(() => {});
|
|
38
|
+
outputResult('Email sent successfully');
|
|
39
|
+
expect(logSpy).toHaveBeenCalledWith('Email sent successfully');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('outputs JSON for objects in human mode (fallback)', () => {
|
|
43
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
44
|
+
value: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
});
|
|
47
|
+
logSpy = spyOn(console, 'log').mockImplementation(() => {});
|
|
48
|
+
outputResult({ id: '123' });
|
|
49
|
+
expect(logSpy).toHaveBeenCalledWith(JSON.stringify({ id: '123' }, null, 2));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('outputError', () => {
|
|
54
|
+
let errorSpy: ReturnType<typeof spyOn>;
|
|
55
|
+
let exitSpy: ReturnType<typeof spyOn>;
|
|
56
|
+
const originalIsTTY = process.stdout.isTTY;
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
errorSpy?.mockRestore();
|
|
60
|
+
exitSpy?.mockRestore();
|
|
61
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
62
|
+
value: originalIsTTY,
|
|
63
|
+
writable: true,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('outputs JSON error when json is true', () => {
|
|
68
|
+
errorSpy = spyOn(console, 'error').mockImplementation(() => {});
|
|
69
|
+
exitSpy = spyOn(process, 'exit').mockImplementation(
|
|
70
|
+
() => undefined as never,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
outputError({ message: 'not found', code: 'not_found' }, { json: true });
|
|
74
|
+
|
|
75
|
+
const expected = JSON.stringify(
|
|
76
|
+
{ error: { message: 'not found', code: 'not_found' } },
|
|
77
|
+
null,
|
|
78
|
+
2,
|
|
79
|
+
);
|
|
80
|
+
expect(errorSpy).toHaveBeenCalledWith(expected);
|
|
81
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('outputs text error when TTY and no json flag', () => {
|
|
85
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
86
|
+
value: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
});
|
|
89
|
+
errorSpy = spyOn(console, 'error').mockImplementation(() => {});
|
|
90
|
+
exitSpy = spyOn(process, 'exit').mockImplementation(
|
|
91
|
+
() => undefined as never,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
outputError({ message: 'something broke' });
|
|
95
|
+
|
|
96
|
+
expect(errorSpy).toHaveBeenCalledWith('Error: something broke');
|
|
97
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('uses custom exit code', () => {
|
|
101
|
+
errorSpy = spyOn(console, 'error').mockImplementation(() => {});
|
|
102
|
+
exitSpy = spyOn(process, 'exit').mockImplementation(
|
|
103
|
+
() => undefined as never,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
outputError({ message: 'error' }, { exitCode: 2, json: true });
|
|
107
|
+
|
|
108
|
+
expect(exitSpy).toHaveBeenCalledWith(2);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('defaults error code to "unknown" when not provided', () => {
|
|
112
|
+
Object.defineProperty(process.stdout, 'isTTY', {
|
|
113
|
+
value: undefined,
|
|
114
|
+
writable: true,
|
|
115
|
+
});
|
|
116
|
+
errorSpy = spyOn(console, 'error').mockImplementation(() => {});
|
|
117
|
+
exitSpy = spyOn(process, 'exit').mockImplementation(
|
|
118
|
+
() => undefined as never,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
outputError({ message: 'oops' });
|
|
122
|
+
|
|
123
|
+
const output = errorSpy.mock.calls[0][0] as string;
|
|
124
|
+
const parsed = JSON.parse(output);
|
|
125
|
+
expect(parsed.error.code).toBe('unknown');
|
|
126
|
+
});
|
|
127
|
+
});
|