@corelayer-ai/cli 0.4.0 → 0.4.1

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.
@@ -0,0 +1,74 @@
1
+ import { readConfig, resolveApiUrl, resolveToken } from "../lib/config.js";
2
+ import { loadSharedSdk } from "../lib/shared-sdk-loader.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 || readConfig().apiUrl);
54
+ const { CorelayerClient } = await loadSharedSdk();
55
+ const client = new CorelayerClient({
56
+ apiKey: token,
57
+ apiUrl,
58
+ timeoutMs: 30_000,
59
+ }, {
60
+ userAgent: "corelayer-cli/0.1.0",
61
+ });
62
+ const created = await client.createApiKey({
63
+ name,
64
+ role,
65
+ expiresAt,
66
+ });
67
+ if (ctx.json) {
68
+ printJson(created);
69
+ return;
70
+ }
71
+ process.stdout.write(`Created API key "${created.apiKey.name}" (${created.apiKey.role}).\n`);
72
+ process.stdout.write("Store this key now. It will not be shown again.\n");
73
+ process.stdout.write(`${created.rawKey}\n`);
74
+ }
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;
@@ -0,0 +1,23 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ let cachedModulePromise = null;
4
+ function resolveSharedSdkPath() {
5
+ const currentFilePath = fileURLToPath(import.meta.url);
6
+ const currentDir = path.dirname(currentFilePath);
7
+ const isBuiltCli = currentDir.includes(`${path.sep}dist${path.sep}`);
8
+ const target = isBuiltCli
9
+ ? path.resolve(currentDir, "../../../dist/src/lib/corelayer-sdk/index.js")
10
+ : path.resolve(currentDir, "../../../src/lib/corelayer-sdk/index.js");
11
+ return pathToFileURL(target).href;
12
+ }
13
+ export async function loadSharedSdk() {
14
+ if (!cachedModulePromise) {
15
+ const sdkPath = resolveSharedSdkPath();
16
+ cachedModulePromise = import(sdkPath).catch(error => {
17
+ throw new Error(`Could not load the Corelayer SDK from ${sdkPath}. ` +
18
+ `Make sure the server has been built with npm run build. ` +
19
+ `Original error: ${error instanceof Error ? error.message : String(error)}`);
20
+ });
21
+ }
22
+ return cachedModulePromise;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corelayer-ai/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Corelayer CLI",
5
5
  "type": "module",
6
6
  "bin": {