@corelayer-ai/cli 0.4.1 → 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.
@@ -1,5 +1,5 @@
1
- import { readConfig, resolveApiUrl, resolveToken } from "../lib/config.js";
2
- import { loadSharedSdk } from "../lib/shared-sdk-loader.js";
1
+ import { CorelayerClient } from "../lib/api-client.js";
2
+ import { resolveApiUrl, resolveToken } from "../lib/config.js";
3
3
  import { fail, printJson } from "../lib/output.js";
4
4
  function readFlag(args, flag) {
5
5
  const index = args.indexOf(flag);
@@ -50,18 +50,11 @@ export async function runApiKeys(args, ctx) {
50
50
  fail("role must be member or admin");
51
51
  }
52
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
- });
53
+ const apiUrl = resolveApiUrl(ctx.apiUrlOverride);
54
+ const client = new CorelayerClient(apiUrl, token);
62
55
  const created = await client.createApiKey({
63
- name,
64
- role,
56
+ name: name,
57
+ role: role,
65
58
  expiresAt,
66
59
  });
67
60
  if (ctx.json) {
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corelayer-ai/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Corelayer CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,23 +0,0 @@
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
- }