Skip to content

Commit 89cdfc7

Browse files
committed
Add API Keys enable command
1 parent ed8e27b commit 89cdfc7

12 files changed

Lines changed: 554 additions & 66 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"clerk": minor
3+
---
4+
5+
Add `clerk enable api-keys` and `clerk disable api-keys` for toggling API Keys on the linked instance. API Key targeting uses the canonical plural `orgs` and `users` values, while the singular `org` and `user` values continue to work as aliases.

packages/cli-core/src/cli-program.ts

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { update } from "./commands/update/index.ts";
4848
import { isClerkSkillInstalled } from "./lib/skill-detection.ts";
4949
import { orgsEnable, orgsDisable } from "./commands/orgs/index.ts";
5050
import { billingEnable, billingDisable } from "./commands/billing/index.ts";
51+
import { apiKeysEnable, apiKeysDisable } from "./commands/api-keys/index.ts";
5152
import { registerExtras } from "@clerk/cli-extras";
5253

5354
const USER_LIST_ORDER_BY_FIELDS = [
@@ -629,13 +630,17 @@ Give AI agents better Clerk context: install the Clerk skills
629630
description: "Enable organizations with options",
630631
},
631632
{
632-
command: "clerk enable billing --for org",
633+
command: "clerk enable billing --for orgs",
633634
description: "Enable billing for organizations only",
634635
},
635636
{
636637
command: "clerk enable billing",
637638
description: "Enable billing for organizations and users",
638639
},
640+
{
641+
command: "clerk enable api-keys",
642+
description: "Enable API Keys for users",
643+
},
639644
]);
640645

641646
enable
@@ -672,7 +677,7 @@ Give AI agents better Clerk context: install the Clerk skills
672677
.description("Enable billing for organizations and/or users")
673678
.option(
674679
"--for <targets...>",
675-
"Billing targets (org and/or user), separated by spaces or commas (e.g. org user). Defaults to both when omitted.",
680+
"Billing targets (orgs and/or users), separated by spaces or commas (e.g. orgs users). Defaults to both when omitted.",
676681
)
677682
.option("--app <id>", "Application ID to target")
678683
.option("--instance <id>", "Instance to target (dev, prod, or instance ID)")
@@ -685,15 +690,15 @@ Give AI agents better Clerk context: install the Clerk skills
685690
description: "Enable billing for organizations and users",
686691
},
687692
{
688-
command: "clerk enable billing --for org",
693+
command: "clerk enable billing --for orgs",
689694
description: "Enable billing for organizations only",
690695
},
691696
{
692-
command: "clerk enable billing --for user",
697+
command: "clerk enable billing --for users",
693698
description: "Enable billing for users only",
694699
},
695700
{
696-
command: "clerk enable billing --for org user",
701+
command: "clerk enable billing --for orgs users",
697702
description: "Enable billing for both targets",
698703
},
699704
{
@@ -703,19 +708,55 @@ Give AI agents better Clerk context: install the Clerk skills
703708
])
704709
.action(billingEnable);
705710

711+
enable
712+
.command("api-keys")
713+
.aliases(["apikeys", "api_keys"])
714+
.description("Enable API Keys on the linked instance")
715+
.option(
716+
"--for <targets...>",
717+
"API Keys targets (orgs and/or users), separated by spaces or commas (e.g. orgs users). Defaults to users when omitted.",
718+
)
719+
.option("--app <id>", "Application ID to target")
720+
.option("--instance <id>", "Instance to target (dev, prod, or instance ID)")
721+
.option("--yes", "Skip confirmation prompts")
722+
.option("--dry-run", "Show the patch that would be sent without applying it")
723+
.setExamples([
724+
{
725+
command: "clerk enable api-keys",
726+
description: "Enable API Keys for users",
727+
},
728+
{
729+
command: "clerk enable api-keys --for orgs",
730+
description: "Enable API Keys for organizations",
731+
},
732+
{
733+
command: "clerk enable api-keys --for users orgs",
734+
description: "Enable API Keys for users and organizations",
735+
},
736+
{
737+
command: "clerk enable api-keys --dry-run",
738+
description: "Preview the patch without applying it",
739+
},
740+
])
741+
.action(apiKeysEnable);
742+
706743
const disable = program
707744
.command("disable")
708745
.description("Disable Clerk features on the linked instance")
709746
.setExamples([
710747
{ command: "clerk disable orgs", description: "Disable organizations" },
711748
{
712-
command: "clerk disable billing --for org",
749+
command: "clerk disable billing --for orgs",
713750
description: "Disable billing for organizations only (leaves organizations enabled)",
714751
},
715752
{
716753
command: "clerk disable billing",
717754
description: "Disable billing for organizations and users",
718755
},
756+
{
757+
command: "clerk disable api-keys",
758+
description: "Disable API Keys",
759+
},
719760
]);
720761

721762
disable
@@ -742,7 +783,7 @@ Give AI agents better Clerk context: install the Clerk skills
742783
)
743784
.option(
744785
"--for <targets...>",
745-
"Billing targets (org and/or user), separated by spaces or commas (e.g. org user). Defaults to both when omitted.",
786+
"Billing targets (orgs and/or users), separated by spaces or commas (e.g. orgs users). Defaults to both when omitted.",
746787
)
747788
.option("--app <id>", "Application ID to target")
748789
.option("--instance <id>", "Instance to target (dev, prod, or instance ID)")
@@ -754,16 +795,44 @@ Give AI agents better Clerk context: install the Clerk skills
754795
description: "Disable billing for organizations and users",
755796
},
756797
{
757-
command: "clerk disable billing --for org",
798+
command: "clerk disable billing --for orgs",
758799
description: "Disable billing for organizations only",
759800
},
760801
{
761-
command: "clerk disable billing --for user",
802+
command: "clerk disable billing --for users",
762803
description: "Disable billing for users only",
763804
},
764805
])
765806
.action(billingDisable);
766807

808+
disable
809+
.command("api-keys")
810+
.aliases(["apikeys", "api_keys"])
811+
.description("Disable API Keys on the linked instance")
812+
.option(
813+
"--for <targets...>",
814+
"API Keys targets (orgs and/or users), separated by spaces or commas (e.g. orgs users). Omit to disable API Keys entirely.",
815+
)
816+
.option("--app <id>", "Application ID to target")
817+
.option("--instance <id>", "Instance to target (dev, prod, or instance ID)")
818+
.option("--yes", "Skip confirmation prompts")
819+
.option("--dry-run", "Show the patch that would be sent without applying it")
820+
.setExamples([
821+
{
822+
command: "clerk disable api-keys",
823+
description: "Disable API Keys entirely",
824+
},
825+
{
826+
command: "clerk disable api-keys --for orgs",
827+
description: "Disable API Keys for organizations only",
828+
},
829+
{
830+
command: "clerk disable api-keys --for users",
831+
description: "Disable API Keys for users only",
832+
},
833+
])
834+
.action(apiKeysDisable);
835+
767836
program
768837
.command("api")
769838
.description("Make authenticated requests to the Clerk API")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# clerk api-keys (enable/disable)
2+
3+
Toggle Clerk API Keys on the linked instance. The handlers are wired to
4+
top-level `clerk enable api-keys` and `clerk disable api-keys` commands.
5+
6+
For arbitrary API Keys settings edits, use
7+
`clerk config patch --json '{"api_keys_settings":{...}}'`.
8+
9+
## Usage
10+
11+
```sh
12+
clerk enable api-keys [--for <targets>] [options]
13+
clerk disable api-keys [--for <targets>] [options]
14+
```
15+
16+
`<targets>` is `orgs` and/or `users`, accepted as space-separated,
17+
comma-separated, or repeated `--for` flags. The singular aliases `org` and
18+
`user` are also accepted for backwards compatibility.
19+
20+
```sh
21+
clerk enable api-keys # defaults to users
22+
clerk enable api-keys --for orgs users
23+
clerk enable api-keys --for orgs,users
24+
clerk disable api-keys # disables API Keys entirely
25+
clerk disable api-keys --for orgs # disables only organization API Keys
26+
```
27+
28+
## Options
29+
30+
| Flag | Description |
31+
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
32+
| `--for <targets>` | Targets (`orgs` and/or `users`), separated by spaces or commas. Enable defaults to users; disable without `--for` disables API Keys entirely. |
33+
| `--app <id>` | Target a specific application |
34+
| `--instance <id>` | Target a specific instance (dev, prod) |
35+
| `--yes` | Skip the confirmation prompt |
36+
| `--dry-run` | Preview the patch without applying it |
37+
38+
## Cascade behavior
39+
40+
- `enable api-keys --for orgs` also sets `organization_settings.enabled = true`.
41+
Organization API Keys require organizations enabled, so this saves a separate
42+
command. The cascade is idempotent.
43+
- `disable api-keys --for orgs` disables only organization API Keys and leaves
44+
organizations enabled.
45+
- `disable api-keys` without `--for` disables API Keys entirely.
46+
47+
## Clerk API endpoints
48+
49+
| Method | Endpoint | Description |
50+
| ------ | ----------------------------------------------------------------- | ----------------------------------------------------------------------- |
51+
| GET | `/v1/platform/applications/{appId}/instances/{instanceId}/config` | Fetch current config for diff before mutation |
52+
| PATCH | `/v1/platform/applications/{appId}/instances/{instanceId}/config` | Patch `api_keys_settings.*` (with `?dry_run=true` when `--dry-run` set) |

0 commit comments

Comments
 (0)