create-hedgeboard 1.0.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.
Files changed (2) hide show
  1. package/index.js +185 -0
  2. package/package.json +17 -0
package/index.js ADDED
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * create-hedgeboard
5
+ *
6
+ * Sets up a HedgeBoard workspace with your API key pre-configured.
7
+ *
8
+ * Usage:
9
+ * npx create-hedgeboard --key YOUR_API_KEY
10
+ * npx create-hedgeboard --key YOUR_API_KEY --dir ./my-workspace
11
+ */
12
+
13
+ const https = require("https");
14
+ const fs = require("fs");
15
+ const path = require("path");
16
+
17
+ // ---------------------------------------------------------------------------
18
+ // Config
19
+ // ---------------------------------------------------------------------------
20
+
21
+ const API_BASE =
22
+ process.env.HEDGEBOARD_API_URL ||
23
+ "https://3oy6d0glul.execute-api.us-east-1.amazonaws.com/v1";
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // CLI args
27
+ // ---------------------------------------------------------------------------
28
+
29
+ function parseArgs() {
30
+ const args = process.argv.slice(2);
31
+ const opts = { key: "", dir: "./hedgeboard" };
32
+
33
+ for (let i = 0; i < args.length; i++) {
34
+ if ((args[i] === "--key" || args[i] === "-k") && args[i + 1]) {
35
+ opts.key = args[++i];
36
+ } else if ((args[i] === "--dir" || args[i] === "-d") && args[i + 1]) {
37
+ opts.dir = args[++i];
38
+ } else if (args[i] === "--help" || args[i] === "-h") {
39
+ console.log(`
40
+ create-hedgeboard — set up a HedgeBoard workspace
41
+
42
+ Usage:
43
+ npx create-hedgeboard --key YOUR_API_KEY
44
+ npx create-hedgeboard --key YOUR_API_KEY --dir ./my-workspace
45
+
46
+ Options:
47
+ --key, -k Your HedgeBoard API key (required)
48
+ --dir, -d Output directory (default: ./hedgeboard)
49
+ --help, -h Show this help
50
+ `);
51
+ process.exit(0);
52
+ }
53
+ }
54
+
55
+ if (!opts.key) {
56
+ console.error(
57
+ "Error: --key is required.\n" +
58
+ " Get your API key at https://hedgeboard.com/dashboard\n\n" +
59
+ " Usage: npx create-hedgeboard --key YOUR_API_KEY"
60
+ );
61
+ process.exit(1);
62
+ }
63
+
64
+ return opts;
65
+ }
66
+
67
+ // ---------------------------------------------------------------------------
68
+ // HTTP helpers
69
+ // ---------------------------------------------------------------------------
70
+
71
+ function fetchBuffer(url, headers = {}) {
72
+ return new Promise((resolve, reject) => {
73
+ const get = (u) => {
74
+ const mod = u.startsWith("https") ? https : require("http");
75
+ mod.get(u, { headers }, (res) => {
76
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
77
+ return get(res.headers.location); // follow redirect
78
+ }
79
+ if (res.statusCode !== 200) {
80
+ return reject(new Error(`HTTP ${res.statusCode}`));
81
+ }
82
+ const chunks = [];
83
+ res.on("data", (c) => chunks.push(c));
84
+ res.on("end", () => resolve(Buffer.concat(chunks)));
85
+ res.on("error", reject);
86
+ }).on("error", reject);
87
+ };
88
+ get(url);
89
+ });
90
+ }
91
+
92
+ // ---------------------------------------------------------------------------
93
+ // ZIP extraction (pure JS, no dependencies)
94
+ // ---------------------------------------------------------------------------
95
+
96
+ function extractZip(zipBuffer, destDir) {
97
+ // Simple ZIP parser — handles DEFLATE and STORE methods
98
+ // For robustness in production, consider using a proper zip library
99
+ const { execSync } = require("child_process");
100
+ const tmpZip = path.join(require("os").tmpdir(), `hedgeboard-${Date.now()}.zip`);
101
+ fs.writeFileSync(tmpZip, zipBuffer);
102
+ fs.mkdirSync(destDir, { recursive: true });
103
+ execSync(`unzip -o -q "${tmpZip}" -d "${destDir}"`);
104
+ fs.unlinkSync(tmpZip);
105
+ }
106
+
107
+ // ---------------------------------------------------------------------------
108
+ // Main
109
+ // ---------------------------------------------------------------------------
110
+
111
+ async function main() {
112
+ const { key, dir } = parseArgs();
113
+
114
+ console.log("\n ╔══════════════════════════════════════╗");
115
+ console.log(" ║ create-hedgeboard ║");
116
+ console.log(" ╚══════════════════════════════════════╝\n");
117
+
118
+ // 1. Validate API key
119
+ process.stdout.write(" → Validating API key... ");
120
+ try {
121
+ const brandData = await fetchBuffer(`${API_BASE}/brand?key=${key}`);
122
+ const brand = JSON.parse(brandData.toString());
123
+ if (brand.error) throw new Error(brand.error);
124
+ console.log("✓");
125
+ } catch (err) {
126
+ console.log("✗");
127
+ console.error(`\n Error: Invalid API key. Check your key at https://hedgeboard.com/dashboard`);
128
+ process.exit(1);
129
+ }
130
+
131
+ // 2. Download toolkit
132
+ process.stdout.write(" → Downloading toolkit... ");
133
+ let zipBuffer;
134
+ try {
135
+ // Download the base toolkit from the HedgeBoard API
136
+ zipBuffer = await fetchBuffer(`${API_BASE}/toolkit`, {
137
+ "x-api-key": key,
138
+ });
139
+ console.log(`✓ (${(zipBuffer.length / 1024).toFixed(0)} KB)`);
140
+ } catch {
141
+ // Fallback: download directly from S3
142
+ try {
143
+ zipBuffer = await fetchBuffer(
144
+ "https://hedgeboard-sec-filings.s3.amazonaws.com/toolkit/hedgeboard-base.zip"
145
+ );
146
+ console.log(`✓ (${(zipBuffer.length / 1024).toFixed(0)} KB)`);
147
+ } catch (err) {
148
+ console.log("✗");
149
+ console.error("\n Error: Failed to download toolkit. Check your internet connection.");
150
+ process.exit(1);
151
+ }
152
+ }
153
+
154
+ // 3. Extract
155
+ const absDir = path.resolve(dir);
156
+ process.stdout.write(` → Extracting to ${absDir}... `);
157
+ try {
158
+ extractZip(zipBuffer, path.dirname(absDir));
159
+ // The ZIP contains hedgeboard/ so files land in the right place
160
+ console.log("✓");
161
+ } catch (err) {
162
+ console.log("✗");
163
+ console.error("\n Error: Failed to extract toolkit.", err.message);
164
+ process.exit(1);
165
+ }
166
+
167
+ // 4. Write .env with the user's API key
168
+ const envPath = path.join(absDir, ".env");
169
+ fs.writeFileSync(
170
+ envPath,
171
+ `# HedgeBoard API\nHEDGEBOARD_API_KEY=${key}\nHEDGEBOARD_API_URL=${API_BASE}\n`
172
+ );
173
+
174
+ // 5. Done!
175
+ console.log("\n ✅ HedgeBoard workspace ready!\n");
176
+ console.log(" Next steps:");
177
+ console.log(` 1. Open ${dir}/ in Claude Code`);
178
+ console.log(` 2. Ask: "Give me a company overview of Apple"`);
179
+ console.log("");
180
+ }
181
+
182
+ main().catch((err) => {
183
+ console.error("\n Unexpected error:", err.message);
184
+ process.exit(1);
185
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "create-hedgeboard",
3
+ "version": "1.0.0",
4
+ "description": "Set up a HedgeBoard financial intelligence workspace",
5
+ "bin": {
6
+ "create-hedgeboard": "./index.js"
7
+ },
8
+ "keywords": [
9
+ "hedgeboard",
10
+ "finance",
11
+ "ai",
12
+ "claude",
13
+ "sec",
14
+ "edgar"
15
+ ],
16
+ "license": "MIT"
17
+ }