@easybits.cloud/cli 0.1.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/index.d.ts +1 -0
- package/dist/index.js +189 -0
- package/package.json +36 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import {
|
|
5
|
+
EasybitsError,
|
|
6
|
+
writeRcConfig,
|
|
7
|
+
resolveApiKey,
|
|
8
|
+
resolveBaseUrl,
|
|
9
|
+
createClientFromEnv
|
|
10
|
+
} from "@easybits.cloud/sdk";
|
|
11
|
+
import { readFileSync, existsSync, statSync } from "fs";
|
|
12
|
+
async function getClient() {
|
|
13
|
+
try {
|
|
14
|
+
return await createClientFromEnv();
|
|
15
|
+
} catch {
|
|
16
|
+
console.error("Not logged in. Run: easybits login <api-key>");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function login() {
|
|
21
|
+
const key = process.argv[3];
|
|
22
|
+
if (!key) {
|
|
23
|
+
console.error("Usage: easybits login <api-key>");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
await writeRcConfig({ apiKey: key });
|
|
27
|
+
console.log("Saved API key to ~/.easybitsrc");
|
|
28
|
+
}
|
|
29
|
+
async function filesList() {
|
|
30
|
+
const client = await getClient();
|
|
31
|
+
try {
|
|
32
|
+
const data = await client.listFiles();
|
|
33
|
+
if (data.items.length === 0) {
|
|
34
|
+
console.log("No files found");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.log(
|
|
38
|
+
`${"Name".padEnd(30)} ${"Size".padEnd(10)} ${"Status".padEnd(10)} ID`
|
|
39
|
+
);
|
|
40
|
+
console.log("-".repeat(70));
|
|
41
|
+
for (const f of data.items) {
|
|
42
|
+
const size = f.size < 1024 * 1024 ? `${(f.size / 1024).toFixed(1)}KB` : `${(f.size / (1024 * 1024)).toFixed(1)}MB`;
|
|
43
|
+
console.log(
|
|
44
|
+
`${f.name.slice(0, 29).padEnd(30)} ${size.padEnd(10)} ${f.status.padEnd(10)} ${f.id}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
if (err instanceof EasybitsError) {
|
|
49
|
+
console.error(`Error ${err.status}: ${err.body}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function filesUpload() {
|
|
56
|
+
const fileName = process.argv[4];
|
|
57
|
+
if (!fileName) {
|
|
58
|
+
console.error("Usage: easybits files upload <filename>");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
if (!existsSync(fileName)) {
|
|
62
|
+
console.error(`File not found: ${fileName}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const stat = statSync(fileName);
|
|
66
|
+
const ext = fileName.split(".").pop() || "";
|
|
67
|
+
const mimeMap = {
|
|
68
|
+
pdf: "application/pdf",
|
|
69
|
+
png: "image/png",
|
|
70
|
+
jpg: "image/jpeg",
|
|
71
|
+
jpeg: "image/jpeg",
|
|
72
|
+
mp4: "video/mp4",
|
|
73
|
+
zip: "application/zip"
|
|
74
|
+
};
|
|
75
|
+
const contentType = mimeMap[ext] || "application/octet-stream";
|
|
76
|
+
const client = await getClient();
|
|
77
|
+
try {
|
|
78
|
+
const data = await client.uploadFile({
|
|
79
|
+
fileName: fileName.split("/").pop(),
|
|
80
|
+
contentType,
|
|
81
|
+
size: stat.size
|
|
82
|
+
});
|
|
83
|
+
const fileBuffer = readFileSync(fileName);
|
|
84
|
+
const uploadRes = await fetch(data.putUrl, {
|
|
85
|
+
method: "PUT",
|
|
86
|
+
body: fileBuffer,
|
|
87
|
+
headers: { "Content-Type": contentType }
|
|
88
|
+
});
|
|
89
|
+
if (uploadRes.ok) {
|
|
90
|
+
console.log(`Uploaded: ${data.file.id}`);
|
|
91
|
+
} else {
|
|
92
|
+
console.error(`Upload failed: ${uploadRes.status}`);
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof EasybitsError) {
|
|
96
|
+
console.error(`Error ${err.status}: ${err.body}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function filesDelete() {
|
|
103
|
+
const fileId = process.argv[4];
|
|
104
|
+
if (!fileId) {
|
|
105
|
+
console.error("Usage: easybits files delete <file-id>");
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
const client = await getClient();
|
|
109
|
+
try {
|
|
110
|
+
await client.deleteFile(fileId);
|
|
111
|
+
console.log("Deleted");
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err instanceof EasybitsError) {
|
|
114
|
+
console.error(`Error ${err.status}: ${err.body}`);
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function providersList() {
|
|
121
|
+
console.log("Default provider: Tigris (platform)");
|
|
122
|
+
console.log("Use the Developer Dashboard to add custom providers.");
|
|
123
|
+
}
|
|
124
|
+
async function printMcpConfig() {
|
|
125
|
+
const apiKey = await resolveApiKey();
|
|
126
|
+
const baseUrl = await resolveBaseUrl();
|
|
127
|
+
const config = {
|
|
128
|
+
mcpServers: {
|
|
129
|
+
easybits: {
|
|
130
|
+
type: "streamable-http",
|
|
131
|
+
url: `${baseUrl}/api/mcp`,
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Bearer ${apiKey || "eb_sk_live_YOUR_KEY"}`
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
console.log(JSON.stringify(config, null, 2));
|
|
139
|
+
}
|
|
140
|
+
function printMcpStdioConfig() {
|
|
141
|
+
const config = {
|
|
142
|
+
mcpServers: {
|
|
143
|
+
easybits: {
|
|
144
|
+
command: "npx",
|
|
145
|
+
args: ["-y", "@easybits.cloud/mcp"],
|
|
146
|
+
env: {
|
|
147
|
+
EASYBITS_API_KEY: "eb_sk_live_YOUR_KEY"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
console.log(JSON.stringify(config, null, 2));
|
|
153
|
+
}
|
|
154
|
+
var [cmd, sub] = [process.argv[2], process.argv[3]];
|
|
155
|
+
switch (cmd) {
|
|
156
|
+
case "login":
|
|
157
|
+
login();
|
|
158
|
+
break;
|
|
159
|
+
case "files":
|
|
160
|
+
if (sub === "list" || !sub) filesList();
|
|
161
|
+
else if (sub === "upload") filesUpload();
|
|
162
|
+
else if (sub === "delete") filesDelete();
|
|
163
|
+
else console.error(`Unknown: files ${sub}`);
|
|
164
|
+
break;
|
|
165
|
+
case "providers":
|
|
166
|
+
providersList();
|
|
167
|
+
break;
|
|
168
|
+
case "config":
|
|
169
|
+
printMcpConfig();
|
|
170
|
+
break;
|
|
171
|
+
case "mcp":
|
|
172
|
+
printMcpStdioConfig();
|
|
173
|
+
break;
|
|
174
|
+
case "help":
|
|
175
|
+
case void 0:
|
|
176
|
+
console.log(`easybits CLI \u2014 @easybits.cloud/cli
|
|
177
|
+
|
|
178
|
+
Commands:
|
|
179
|
+
login <key> Save API key
|
|
180
|
+
files list List your files
|
|
181
|
+
files upload <f> Upload a file
|
|
182
|
+
files delete <id> Delete a file
|
|
183
|
+
providers list Show storage providers
|
|
184
|
+
config Print MCP config JSON (streamable HTTP)
|
|
185
|
+
mcp Print MCP stdio config JSON`);
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
console.error(`Unknown command: ${cmd}. Run 'easybits help'`);
|
|
189
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easybits.cloud/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official CLI for Easybits — manage files, storage, and MCP from your terminal",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"easybits": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"easybits",
|
|
14
|
+
"cli",
|
|
15
|
+
"file-management",
|
|
16
|
+
"mcp",
|
|
17
|
+
"digital-assets"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/easybits-cloud/easybits",
|
|
22
|
+
"directory": "cli"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
27
|
+
"dev": "tsup src/index.ts --format esm --watch"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@easybits.cloud/sdk": "^0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.7.0"
|
|
35
|
+
}
|
|
36
|
+
}
|