apiforge-analyzer 1.1.0 → 1.2.1
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/cjs/cli.js +425 -255
- package/dist/cjs/detect.js +68 -48
- package/dist/cjs/frameworks/express.js +80 -74
- package/dist/cjs/index.js +118 -58
- package/dist/cjs/uploader.js +49 -11
- package/dist/esm/cli.js +424 -257
- package/dist/esm/detect.js +68 -48
- package/dist/esm/frameworks/express.js +80 -74
- package/dist/esm/index.js +120 -60
- package/dist/esm/uploader.js +47 -11
- package/dist/types/detect.d.ts +3 -5
- package/dist/types/frameworks/express.d.ts +2 -2
- package/dist/types/index.d.ts +1 -4
- package/dist/types/uploader.d.ts +10 -2
- package/package.json +1 -1
package/dist/cjs/uploader.js
CHANGED
|
@@ -3,32 +3,70 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeStatusFile = writeStatusFile;
|
|
7
|
+
exports.removeStatusFile = removeStatusFile;
|
|
6
8
|
exports.uploadRoutes = uploadRoutes;
|
|
7
9
|
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
8
12
|
const export_js_1 = require("./export.js");
|
|
13
|
+
/** Status file written to the project root so the CLI can detect completion. */
|
|
14
|
+
const STATUS_FILE = '.apiforge-status.json';
|
|
15
|
+
function writeStatusFile(status, data) {
|
|
16
|
+
try {
|
|
17
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(process.cwd(), STATUS_FILE), JSON.stringify({ status, timestamp: Date.now(), ...data }), 'utf-8');
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
}
|
|
21
|
+
function removeStatusFile() {
|
|
22
|
+
try {
|
|
23
|
+
const p = (0, path_1.join)(process.cwd(), STATUS_FILE);
|
|
24
|
+
if ((0, fs_1.existsSync)(p))
|
|
25
|
+
(0, fs_1.unlinkSync)(p);
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
9
29
|
/**
|
|
10
|
-
*
|
|
30
|
+
* Submit routes to the APIForge backend for user review.
|
|
31
|
+
* Returns the pendingImportId so the CLI can poll for approval.
|
|
11
32
|
*/
|
|
12
33
|
async function uploadRoutes(routes, options) {
|
|
13
|
-
|
|
34
|
+
// Production URL is the built-in default — no config needed.
|
|
35
|
+
// Override only for local testing via option or env var.
|
|
36
|
+
const backendUrl = (options.apiForgeUrl ||
|
|
37
|
+
process.env.APIFORGE_URL ||
|
|
38
|
+
'https://apiforgeapi.brainfogagency.com').replace(/\/$/, '');
|
|
14
39
|
const enrichedRoutes = (0, export_js_1.enrichRoutes)(routes);
|
|
40
|
+
const payload = {
|
|
41
|
+
projectName: options.projectName,
|
|
42
|
+
routes: enrichedRoutes,
|
|
43
|
+
baseUrl: options.baseUrl,
|
|
44
|
+
framework: enrichedRoutes[0]?.framework || 'unknown',
|
|
45
|
+
};
|
|
15
46
|
try {
|
|
16
|
-
const response = await axios_1.default.post(`${
|
|
17
|
-
projectName: options.projectName,
|
|
18
|
-
routes: enrichedRoutes,
|
|
19
|
-
baseUrl: options.baseUrl,
|
|
20
|
-
framework: enrichedRoutes[0]?.framework || 'unknown',
|
|
21
|
-
}, {
|
|
47
|
+
const response = await axios_1.default.post(`${backendUrl}/api/cli/submit`, payload, {
|
|
22
48
|
headers: {
|
|
23
49
|
'Content-Type': 'application/json',
|
|
24
50
|
'X-API-Key': options.apiKey,
|
|
51
|
+
'User-Agent': 'apiforge-analyzer/1.2.0',
|
|
25
52
|
},
|
|
26
53
|
timeout: 30000,
|
|
27
54
|
});
|
|
28
|
-
|
|
55
|
+
const data = response.data?.data;
|
|
56
|
+
console.log(`✅ APIForge: ${data?.message || 'Routes submitted for review'}`);
|
|
57
|
+
writeStatusFile('submitted', {
|
|
58
|
+
pendingImportId: data.pendingImportId,
|
|
59
|
+
routeCount: data.routeCount,
|
|
60
|
+
});
|
|
61
|
+
return data;
|
|
29
62
|
}
|
|
30
63
|
catch (error) {
|
|
31
|
-
|
|
32
|
-
|
|
64
|
+
const msg = error.response?.data?.message ||
|
|
65
|
+
error.response?.data?.error ||
|
|
66
|
+
error.message ||
|
|
67
|
+
'Unknown error';
|
|
68
|
+
console.error(`❌ APIForge upload failed: ${msg}`);
|
|
69
|
+
writeStatusFile('error', { error: msg });
|
|
70
|
+
return null;
|
|
33
71
|
}
|
|
34
72
|
}
|