@corelayer-ai/cli 0.4.0 → 0.4.2
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/dist/commands/api-keys.js +67 -0
- package/dist/index.js +5 -0
- package/dist/lib/api-client.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CorelayerClient } from "../lib/api-client.js";
|
|
2
|
+
import { resolveApiUrl, resolveToken } from "../lib/config.js";
|
|
3
|
+
import { fail, printJson } from "../lib/output.js";
|
|
4
|
+
function readFlag(args, flag) {
|
|
5
|
+
const index = args.indexOf(flag);
|
|
6
|
+
if (index === -1)
|
|
7
|
+
return undefined;
|
|
8
|
+
return args[index + 1];
|
|
9
|
+
}
|
|
10
|
+
function printHelp() {
|
|
11
|
+
process.stdout.write(`corelayer api-keys - Manage Corelayer API keys
|
|
12
|
+
|
|
13
|
+
USAGE:
|
|
14
|
+
corelayer api-keys create --name <name> [--role <member|admin>] [--expires-at <iso8601>]
|
|
15
|
+
|
|
16
|
+
SUBCOMMANDS:
|
|
17
|
+
create Create a new API key and print the raw key once
|
|
18
|
+
|
|
19
|
+
OPTIONS:
|
|
20
|
+
--name <name> Display name for the API key
|
|
21
|
+
--role <role> member or admin (default: member)
|
|
22
|
+
--expires-at <value> Optional ISO timestamp for key expiry
|
|
23
|
+
--json Output as JSON
|
|
24
|
+
-h, --help Print help
|
|
25
|
+
|
|
26
|
+
EXAMPLES:
|
|
27
|
+
corelayer api-keys create --name "Claude Desktop MCP"
|
|
28
|
+
corelayer api-keys create --name "Codex MCP" --role member --json
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
export async function runApiKeys(args, ctx) {
|
|
32
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
33
|
+
printHelp();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const sub = args[0];
|
|
37
|
+
if (sub !== "create") {
|
|
38
|
+
fail("Usage: corelayer api-keys create --name <name> [options]");
|
|
39
|
+
}
|
|
40
|
+
const token = resolveToken();
|
|
41
|
+
if (!token) {
|
|
42
|
+
fail("Not authenticated. Set CORELAYER_API_KEY or run: corelayer login");
|
|
43
|
+
}
|
|
44
|
+
const name = readFlag(args, "--name");
|
|
45
|
+
if (!name) {
|
|
46
|
+
fail("Usage: corelayer api-keys create --name <name> [options]");
|
|
47
|
+
}
|
|
48
|
+
const role = readFlag(args, "--role") || "member";
|
|
49
|
+
if (role !== "member" && role !== "admin") {
|
|
50
|
+
fail("role must be member or admin");
|
|
51
|
+
}
|
|
52
|
+
const expiresAt = readFlag(args, "--expires-at");
|
|
53
|
+
const apiUrl = resolveApiUrl(ctx.apiUrlOverride);
|
|
54
|
+
const client = new CorelayerClient(apiUrl, token);
|
|
55
|
+
const created = await client.createApiKey({
|
|
56
|
+
name: name,
|
|
57
|
+
role: role,
|
|
58
|
+
expiresAt,
|
|
59
|
+
});
|
|
60
|
+
if (ctx.json) {
|
|
61
|
+
printJson(created);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
process.stdout.write(`Created API key "${created.apiKey.name}" (${created.apiKey.role}).\n`);
|
|
65
|
+
process.stdout.write("Store this key now. It will not be shown again.\n");
|
|
66
|
+
process.stdout.write(`${created.rawKey}\n`);
|
|
67
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { runApiKeys } from "./commands/api-keys.js";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import { runConfig } from "./commands/config.js";
|
|
4
5
|
import { runGroups } from "./commands/groups.js";
|
|
@@ -19,6 +20,7 @@ USAGE:
|
|
|
19
20
|
COMMANDS:
|
|
20
21
|
login Authenticate with Corelayer (opens browser)
|
|
21
22
|
logout Sign out and clear local credentials
|
|
23
|
+
api-keys Create Corelayer API keys
|
|
22
24
|
groups List and inspect groups
|
|
23
25
|
issues List, inspect, and manage issues
|
|
24
26
|
integrations List integrations for a group
|
|
@@ -111,6 +113,9 @@ async function main() {
|
|
|
111
113
|
case "groups":
|
|
112
114
|
await runGroups(rest, ctx);
|
|
113
115
|
return;
|
|
116
|
+
case "api-keys":
|
|
117
|
+
await runApiKeys(rest, ctx);
|
|
118
|
+
return;
|
|
114
119
|
case "integrations":
|
|
115
120
|
await runIntegrations(rest, ctx);
|
|
116
121
|
return;
|
package/dist/lib/api-client.js
CHANGED
|
@@ -101,6 +101,28 @@ export class CorelayerClient {
|
|
|
101
101
|
async listGroups() {
|
|
102
102
|
return this.request("GET", "/api/v1/groups");
|
|
103
103
|
}
|
|
104
|
+
async createApiKey(params) {
|
|
105
|
+
const data = await this.request("POST", "/api/v1/api-keys", {
|
|
106
|
+
name: params.name,
|
|
107
|
+
role: params.role || "member",
|
|
108
|
+
expires_at: params.expiresAt ?? null,
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
apiKey: {
|
|
112
|
+
id: data.apiKey.id,
|
|
113
|
+
name: data.apiKey.name,
|
|
114
|
+
role: data.apiKey.role,
|
|
115
|
+
keyPrefix: data.apiKey.key_prefix,
|
|
116
|
+
lastUsedAt: data.apiKey.last_used_at ?? null,
|
|
117
|
+
expiresAt: data.apiKey.expires_at ?? null,
|
|
118
|
+
createdAt: data.apiKey.created_at,
|
|
119
|
+
createdBy: data.apiKey.created_by ?? null,
|
|
120
|
+
revokedAt: data.apiKey.revoked_at ?? null,
|
|
121
|
+
revokedBy: data.apiKey.revoked_by ?? null,
|
|
122
|
+
},
|
|
123
|
+
rawKey: data.rawKey,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
104
126
|
async listIntegrations(groupId) {
|
|
105
127
|
const params = new URLSearchParams();
|
|
106
128
|
if (groupId) {
|