evidence-browser-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/bin.js +10 -0
- package/dist/commands/upload.js +44 -0
- package/dist/index.js +15 -0
- package/dist/lib/api-client.js +36 -0
- package/package.json +25 -0
package/dist/bin.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
(0, index_1.createCli)()
|
|
6
|
+
.parseAsync(process.argv)
|
|
7
|
+
.catch((err) => {
|
|
8
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
9
|
+
process.exit(1);
|
|
10
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerUpload = registerUpload;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const api_client_1 = require("../lib/api-client");
|
|
10
|
+
function registerUpload(program) {
|
|
11
|
+
program
|
|
12
|
+
.command("upload <file>")
|
|
13
|
+
.description("Upload a bundle ZIP to an Evidence Browser instance")
|
|
14
|
+
.requiredOption("--url <url>", "Base URL of the Evidence Browser instance (e.g. https://eb.example.com)")
|
|
15
|
+
.requiredOption("--workspace <slug>", "Workspace slug")
|
|
16
|
+
.requiredOption("--api-key <key>", "API key with upload or admin scope (eb_...)")
|
|
17
|
+
.option("--bundle-id <id>", "Override bundle ID (default: derived from filename)")
|
|
18
|
+
.action(async (file, opts) => {
|
|
19
|
+
const absPath = path_1.default.resolve(file);
|
|
20
|
+
if (!fs_1.default.existsSync(absPath)) {
|
|
21
|
+
console.error(`Error: File not found: ${absPath}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
if (!absPath.endsWith(".zip")) {
|
|
25
|
+
console.error("Error: File must be a .zip");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const result = await (0, api_client_1.uploadBundle)({
|
|
30
|
+
filePath: absPath,
|
|
31
|
+
url: opts.url,
|
|
32
|
+
workspace: opts.workspace,
|
|
33
|
+
apiKey: opts.apiKey,
|
|
34
|
+
bundleId: opts.bundleId,
|
|
35
|
+
});
|
|
36
|
+
console.log(`Uploaded: ${result.bundleId}`);
|
|
37
|
+
console.log(` View: ${opts.url.replace(/\/$/, "")}/w/${opts.workspace}/${result.bundleId}`);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCli = createCli;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const upload_1 = require("./commands/upload");
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
7
|
+
const { version } = require("../package.json");
|
|
8
|
+
function createCli() {
|
|
9
|
+
const program = new commander_1.Command()
|
|
10
|
+
.name("eb")
|
|
11
|
+
.description("Evidence Browser CLI")
|
|
12
|
+
.version(version);
|
|
13
|
+
(0, upload_1.registerUpload)(program);
|
|
14
|
+
return program;
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.uploadBundle = uploadBundle;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
async function uploadBundle(opts) {
|
|
10
|
+
const endpoint = `${opts.url.replace(/\/$/, "")}/api/w/${opts.workspace}/bundle`;
|
|
11
|
+
const fileBuffer = fs_1.default.readFileSync(opts.filePath);
|
|
12
|
+
const filename = path_1.default.basename(opts.filePath);
|
|
13
|
+
const form = new FormData();
|
|
14
|
+
form.append("file", new Blob([fileBuffer], { type: "application/zip" }), filename);
|
|
15
|
+
if (opts.bundleId) {
|
|
16
|
+
form.append("bundleId", opts.bundleId);
|
|
17
|
+
}
|
|
18
|
+
const res = await fetch(endpoint, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${opts.apiKey}`,
|
|
22
|
+
},
|
|
23
|
+
body: form,
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const body = await res.json().catch(() => ({}));
|
|
27
|
+
throw new Error(`Upload failed (${res.status}): ${body.error ?? res.statusText}`);
|
|
28
|
+
}
|
|
29
|
+
const data = await res.json();
|
|
30
|
+
// API may return { bundle: { bundleId } } or { bundleId } depending on version
|
|
31
|
+
const bundleId = data.bundle?.bundleId ?? data.bundleId;
|
|
32
|
+
if (!bundleId) {
|
|
33
|
+
throw new Error("Upload succeeded but server did not return a bundleId");
|
|
34
|
+
}
|
|
35
|
+
return { bundleId };
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "evidence-browser-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for uploading bundles to Evidence Browser",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"eb": "./dist/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"commander": "^12.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20",
|
|
23
|
+
"typescript": "^5"
|
|
24
|
+
}
|
|
25
|
+
}
|