@corelayer-ai/cli 0.2.0 → 0.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.
- package/dist/commands/groups.js +4 -5
- package/dist/commands/install-skill.js +1 -1
- package/dist/commands/integrations.js +4 -4
- package/dist/commands/issues.js +4 -4
- package/dist/commands/login.js +27 -0
- package/dist/index.js +16 -2
- package/dist/lib/config.js +7 -1
- package/package.json +1 -1
- package/dist/lib/cli-auth.js +0 -31
package/dist/commands/groups.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { CorelayerClient } from "../lib/api-client.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveToken, resolveApiUrl } from "../lib/config.js";
|
|
3
3
|
import { fail, formatDate, printJson, printTable } from "../lib/output.js";
|
|
4
4
|
export async function runGroups(args, ctx) {
|
|
5
5
|
const sub = args[0];
|
|
6
6
|
if (sub !== "list") {
|
|
7
7
|
fail("Usage: corelayer groups list");
|
|
8
8
|
}
|
|
9
|
-
const
|
|
10
|
-
const token = config.token;
|
|
9
|
+
const token = resolveToken();
|
|
11
10
|
if (!token) {
|
|
12
|
-
fail("Not
|
|
11
|
+
fail("Not authenticated. Set CORELAYER_API_KEY or run: corelayer login");
|
|
13
12
|
}
|
|
14
|
-
const apiUrl = ctx.apiUrlOverride
|
|
13
|
+
const apiUrl = resolveApiUrl(ctx.apiUrlOverride);
|
|
15
14
|
const client = new CorelayerClient(apiUrl, token);
|
|
16
15
|
const result = await client.listGroups();
|
|
17
16
|
if (ctx.json) {
|
|
@@ -23,7 +23,7 @@ export async function runInstallSkill(_args, ctx) {
|
|
|
23
23
|
mkdirSync(targetDir, { recursive: true });
|
|
24
24
|
copyFileSync(source, targetFile);
|
|
25
25
|
if (!ctx.quiet) {
|
|
26
|
-
process.stdout.write(`Corelayer skill installed to ${targetFile}\
|
|
26
|
+
process.stdout.write(`Corelayer skill installed to ${targetFile}\n`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
export async function runUninstallSkill(_args, ctx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CorelayerClient } from "../lib/api-client.js";
|
|
2
|
-
import { readConfig } from "../lib/config.js";
|
|
2
|
+
import { readConfig, resolveToken, resolveApiUrl } from "../lib/config.js";
|
|
3
3
|
import { fail, printJson, printTable } from "../lib/output.js";
|
|
4
4
|
function readFlag(args, flag) {
|
|
5
5
|
const index = args.indexOf(flag);
|
|
@@ -13,12 +13,12 @@ export async function runIntegrations(args, ctx) {
|
|
|
13
13
|
fail("Usage: corelayer integrations list [--group <groupId>]");
|
|
14
14
|
}
|
|
15
15
|
const config = readConfig();
|
|
16
|
-
const token =
|
|
16
|
+
const token = resolveToken();
|
|
17
17
|
if (!token) {
|
|
18
|
-
fail("Not
|
|
18
|
+
fail("Not authenticated. Set CORELAYER_API_KEY or run: corelayer login");
|
|
19
19
|
}
|
|
20
20
|
const groupId = readFlag(args, "--group") || config.defaults?.group;
|
|
21
|
-
const apiUrl = ctx.apiUrlOverride
|
|
21
|
+
const apiUrl = resolveApiUrl(ctx.apiUrlOverride);
|
|
22
22
|
const client = new CorelayerClient(apiUrl, token);
|
|
23
23
|
const result = await client.listIntegrations(groupId);
|
|
24
24
|
if (ctx.json) {
|
package/dist/commands/issues.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import { stdin as input, stdout as output } from "node:process";
|
|
3
3
|
import { CorelayerClient } from "../lib/api-client.js";
|
|
4
|
-
import { readConfig } from "../lib/config.js";
|
|
4
|
+
import { readConfig, resolveToken, resolveApiUrl } from "../lib/config.js";
|
|
5
5
|
import { fail, formatDate, printJson, printTable } from "../lib/output.js";
|
|
6
6
|
function readFlag(args, flag) {
|
|
7
7
|
const index = args.indexOf(flag);
|
|
@@ -48,11 +48,11 @@ async function confirmDelete() {
|
|
|
48
48
|
export async function runIssues(args, ctx) {
|
|
49
49
|
const sub = args[0];
|
|
50
50
|
const config = readConfig();
|
|
51
|
-
const token =
|
|
51
|
+
const token = resolveToken();
|
|
52
52
|
if (!token) {
|
|
53
|
-
fail("Not
|
|
53
|
+
fail("Not authenticated. Set CORELAYER_API_KEY or run: corelayer login");
|
|
54
54
|
}
|
|
55
|
-
const apiUrl = ctx.apiUrlOverride
|
|
55
|
+
const apiUrl = resolveApiUrl(ctx.apiUrlOverride);
|
|
56
56
|
const client = new CorelayerClient(apiUrl, token);
|
|
57
57
|
const commandArgs = removeFlags(args.slice(1));
|
|
58
58
|
if (sub === "list") {
|
package/dist/commands/login.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { loginWithBrowser, loginWithCodeDirect } from "../lib/auth.js";
|
|
2
|
+
import { updateConfig } from "../lib/config.js";
|
|
2
3
|
import { fail } from "../lib/output.js";
|
|
3
4
|
function readFlag(args, flag) {
|
|
4
5
|
const index = args.indexOf(flag);
|
|
@@ -6,8 +7,34 @@ function readFlag(args, flag) {
|
|
|
6
7
|
return undefined;
|
|
7
8
|
return args[index + 1];
|
|
8
9
|
}
|
|
10
|
+
function hasFlag(args, flag) {
|
|
11
|
+
return args.includes(flag);
|
|
12
|
+
}
|
|
13
|
+
async function readStdin() {
|
|
14
|
+
if (process.stdin.isTTY) {
|
|
15
|
+
fail("No token provided on stdin. Usage: echo $CORELAYER_API_KEY | corelayer login --with-token");
|
|
16
|
+
}
|
|
17
|
+
const chunks = [];
|
|
18
|
+
for await (const chunk of process.stdin) {
|
|
19
|
+
chunks.push(chunk);
|
|
20
|
+
}
|
|
21
|
+
return Buffer.concat(chunks).toString("utf8").trim();
|
|
22
|
+
}
|
|
9
23
|
export async function runLogin(args, ctx) {
|
|
10
24
|
const code = readFlag(args, "--code");
|
|
25
|
+
const withToken = hasFlag(args, "--with-token");
|
|
26
|
+
if (withToken) {
|
|
27
|
+
const token = await readStdin();
|
|
28
|
+
if (!token) {
|
|
29
|
+
fail("Empty token. Usage: echo $CORELAYER_API_KEY | corelayer login --with-token");
|
|
30
|
+
}
|
|
31
|
+
const apiUrl = ctx.apiUrlOverride || "https://api.corelayer.com";
|
|
32
|
+
updateConfig({ token, apiUrl });
|
|
33
|
+
if (!ctx.quiet) {
|
|
34
|
+
process.stdout.write(`Token saved. API URL: ${apiUrl}\n`);
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
11
38
|
let email;
|
|
12
39
|
let orgName;
|
|
13
40
|
if (code) {
|
package/dist/index.js
CHANGED
|
@@ -15,19 +15,33 @@ function printHelp() {
|
|
|
15
15
|
Usage:
|
|
16
16
|
corelayer login (opens browser)
|
|
17
17
|
corelayer login --code <CODE> --api-url <url> (manual)
|
|
18
|
+
corelayer login --with-token --api-url <url> (pipe token from stdin)
|
|
18
19
|
corelayer logout
|
|
19
20
|
corelayer issues <list|get|close|reopen|delete|summary> ...
|
|
20
21
|
corelayer groups list
|
|
21
22
|
corelayer integrations list [--group <groupId>]
|
|
22
23
|
corelayer config <get|set> ...
|
|
23
|
-
corelayer install-skill (install
|
|
24
|
-
corelayer uninstall-skill (remove
|
|
24
|
+
corelayer install-skill (install Corelayer skill)
|
|
25
|
+
corelayer uninstall-skill (remove Corelayer skill)
|
|
25
26
|
|
|
26
27
|
Global flags:
|
|
27
28
|
--json
|
|
28
29
|
--quiet, -q
|
|
29
30
|
--api-url <url>
|
|
30
31
|
--no-color
|
|
32
|
+
|
|
33
|
+
Environment variables:
|
|
34
|
+
CORELAYER_API_KEY API key for non-interactive auth (skips login)
|
|
35
|
+
CORELAYER_API_URL Server URL (default: https://api.corelayer.com)
|
|
36
|
+
CORELAYER_AUTH_URL Auth server URL (default: https://app.corelayer.com)
|
|
37
|
+
|
|
38
|
+
Non-interactive auth (CI/CD, agents):
|
|
39
|
+
export CORELAYER_API_KEY=cl_live_...
|
|
40
|
+
export CORELAYER_API_URL=https://api.corelayer.com
|
|
41
|
+
corelayer issues list --group <groupId>
|
|
42
|
+
|
|
43
|
+
Save a token to config:
|
|
44
|
+
echo $CORELAYER_API_KEY | corelayer login --with-token --api-url <url>
|
|
31
45
|
`);
|
|
32
46
|
}
|
|
33
47
|
function parseGlobalFlags(argv) {
|
package/dist/lib/config.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
const CONFIG_DIR = path.join(os.homedir(), ".corelayer");
|
|
5
5
|
const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
6
6
|
function defaultApiUrl() {
|
|
7
|
-
return process.env.CORELAYER_API_URL || "
|
|
7
|
+
return process.env.CORELAYER_API_URL || "https://api.corelayer.com";
|
|
8
8
|
}
|
|
9
9
|
export function getConfigPath() {
|
|
10
10
|
return CONFIG_PATH;
|
|
@@ -52,6 +52,12 @@ export function updateConfig(partial) {
|
|
|
52
52
|
writeConfig(merged);
|
|
53
53
|
return merged;
|
|
54
54
|
}
|
|
55
|
+
export function resolveToken() {
|
|
56
|
+
return process.env.CORELAYER_API_KEY || readConfig().token;
|
|
57
|
+
}
|
|
58
|
+
export function resolveApiUrl(override) {
|
|
59
|
+
return override || readConfig().apiUrl;
|
|
60
|
+
}
|
|
55
61
|
export function clearToken() {
|
|
56
62
|
const current = readConfig();
|
|
57
63
|
delete current.token;
|
package/package.json
CHANGED
package/dist/lib/cli-auth.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
const MAX_CALLBACK_BODY_BYTES = 8 * 1024;
|
|
3
|
-
export function parseTrustedOrigin(authBaseUrl) {
|
|
4
|
-
const parsed = new URL(authBaseUrl);
|
|
5
|
-
return parsed.origin;
|
|
6
|
-
}
|
|
7
|
-
export function hashCliAuthCode(code) {
|
|
8
|
-
return crypto.createHash("sha256").update(code).digest("hex");
|
|
9
|
-
}
|
|
10
|
-
export async function readJsonBody(req) {
|
|
11
|
-
const chunks = [];
|
|
12
|
-
let total = 0;
|
|
13
|
-
for await (const chunk of req) {
|
|
14
|
-
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
15
|
-
total += buffer.length;
|
|
16
|
-
if (total > MAX_CALLBACK_BODY_BYTES) {
|
|
17
|
-
throw new Error("Callback body is too large");
|
|
18
|
-
}
|
|
19
|
-
chunks.push(buffer);
|
|
20
|
-
}
|
|
21
|
-
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
22
|
-
if (!raw) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(raw);
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
throw new Error("Callback body is not valid JSON");
|
|
30
|
-
}
|
|
31
|
-
}
|