create-hedgeboard 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +39 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,10 +18,17 @@ const path = require("path");
18
18
  // Config
19
19
  // ---------------------------------------------------------------------------
20
20
 
21
- const API_BASE =
21
+ const APP_URL =
22
+ process.env.HEDGEBOARD_APP_URL ||
23
+ "https://www.hedgeboardhq.com";
24
+
25
+ const API_URL =
22
26
  process.env.HEDGEBOARD_API_URL ||
23
27
  "https://3oy6d0glul.execute-api.us-east-1.amazonaws.com/v1";
24
28
 
29
+ const S3_TOOLKIT_URL =
30
+ "https://hedgeboard-sec-filings.s3.amazonaws.com/toolkit/hedgeboard-base.zip";
31
+
25
32
  // ---------------------------------------------------------------------------
26
33
  // CLI args
27
34
  // ---------------------------------------------------------------------------
@@ -115,48 +122,51 @@ async function main() {
115
122
  console.log(" ║ create-hedgeboard ║");
116
123
  console.log(" ╚══════════════════════════════════════╝\n");
117
124
 
118
- // 1. Validate API key
125
+ // 1. Validate API key against the app
119
126
  process.stdout.write(" → Validating API key... ");
120
127
  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);
128
+ const resp = await fetchBuffer(`${APP_URL}/api/data-sources?key=${key}`);
129
+ const data = JSON.parse(resp.toString());
130
+ if (data.error) throw new Error(data.error);
124
131
  console.log("✓");
125
132
  } 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);
133
+ console.log("✓ (offline validation skipped)");
129
134
  }
130
135
 
131
- // 2. Download toolkit
136
+ // 2. Download toolkit from S3
132
137
  process.stdout.write(" → Downloading toolkit... ");
133
138
  let zipBuffer;
134
139
  try {
135
- // Download the base toolkit from the HedgeBoard API
136
- zipBuffer = await fetchBuffer(`${API_BASE}/toolkit`, {
137
- "x-api-key": key,
138
- });
140
+ zipBuffer = await fetchBuffer(S3_TOOLKIT_URL);
139
141
  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
- }
142
+ } catch (err) {
143
+ console.log("✗");
144
+ console.error("\n Error: Failed to download toolkit. Check your internet connection.");
145
+ process.exit(1);
152
146
  }
153
147
 
154
- // 3. Extract
148
+ // 3. Extract to temp, then move to target dir
155
149
  const absDir = path.resolve(dir);
156
150
  process.stdout.write(` → Extracting to ${absDir}... `);
157
151
  try {
158
- extractZip(zipBuffer, path.dirname(absDir));
159
- // The ZIP contains hedgeboard/ so files land in the right place
152
+ const tmpDir = path.join(require("os").tmpdir(), `hb-extract-${Date.now()}`);
153
+ extractZip(zipBuffer, tmpDir);
154
+
155
+ // The ZIP contains hedgeboard/ folder — move its contents to target
156
+ const extractedDir = path.join(tmpDir, "hedgeboard");
157
+ if (fs.existsSync(extractedDir)) {
158
+ // Move extracted hedgeboard/ to the user's target dir
159
+ fs.mkdirSync(path.dirname(absDir), { recursive: true });
160
+ if (fs.existsSync(absDir)) {
161
+ // Merge into existing dir
162
+ const { execSync } = require("child_process");
163
+ execSync(`cp -r "${extractedDir}/"* "${absDir}/"`);
164
+ } else {
165
+ fs.renameSync(extractedDir, absDir);
166
+ }
167
+ }
168
+ // Cleanup temp
169
+ fs.rmSync(tmpDir, { recursive: true, force: true });
160
170
  console.log("✓");
161
171
  } catch (err) {
162
172
  console.log("✗");
@@ -168,7 +178,7 @@ async function main() {
168
178
  const envPath = path.join(absDir, ".env");
169
179
  fs.writeFileSync(
170
180
  envPath,
171
- `# HedgeBoard API\nHEDGEBOARD_API_KEY=${key}\nHEDGEBOARD_API_URL=${API_BASE}\n`
181
+ `# HedgeBoard API\nHEDGEBOARD_API_KEY=${key}\nHEDGEBOARD_API_URL=${API_URL}\n`
172
182
  );
173
183
 
174
184
  // 5. Done!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-hedgeboard",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Set up a HedgeBoard financial intelligence workspace",
5
5
  "bin": {
6
6
  "create-hedgeboard": "./index.js"