botversion-sdk 2.0.0 → 2.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/bin/scan-backend.js +75 -0
- package/bin/scan-frontend.js +24 -7
- package/client.js +1 -1
- package/index.js +2 -1
- package/interceptor.js +30 -12
- package/package.json +4 -2
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var path = require("path");
|
|
5
|
+
var fs = require("fs");
|
|
6
|
+
var sdk = require("../index");
|
|
7
|
+
var BotVersionClient = require("../client");
|
|
8
|
+
|
|
9
|
+
// Auto-load env files from the customer's project, same precedence Next.js
|
|
10
|
+
// uses: .env first, then .env.local (which is allowed to override .env).
|
|
11
|
+
// dotenv.config() never overwrites a variable already set in process.env,
|
|
12
|
+
// so if the customer already exported the key in their shell/CI, that
|
|
13
|
+
// still takes priority over anything in these files.
|
|
14
|
+
(function loadEnvFiles() {
|
|
15
|
+
var dotenv;
|
|
16
|
+
try {
|
|
17
|
+
dotenv = require("dotenv");
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return; // dotenv not installed for some reason — skip silently
|
|
20
|
+
}
|
|
21
|
+
var cwd = process.cwd();
|
|
22
|
+
[".env", ".env.local"].forEach(function (file) {
|
|
23
|
+
var filePath = path.join(cwd, file);
|
|
24
|
+
if (fs.existsSync(filePath)) {
|
|
25
|
+
dotenv.config({ path: filePath });
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
})();
|
|
29
|
+
|
|
30
|
+
var apiKey = process.env.BOTVERSION_API_KEY;
|
|
31
|
+
var platformUrl =
|
|
32
|
+
process.env.BOTVERSION_PLATFORM_URL || "https://console.botversion.com";
|
|
33
|
+
|
|
34
|
+
if (!apiKey) {
|
|
35
|
+
console.error(
|
|
36
|
+
"[BotVersion] BOTVERSION_API_KEY environment variable is not set. Skipping backend endpoint scan.",
|
|
37
|
+
);
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var cwd = process.cwd();
|
|
42
|
+
var client = new BotVersionClient({ apiKey: apiKey, platformUrl: platformUrl });
|
|
43
|
+
|
|
44
|
+
var detected = sdk.detectFrameworks(cwd);
|
|
45
|
+
var projectType = sdk.classifyInstallation(detected.backend, detected.frontend);
|
|
46
|
+
|
|
47
|
+
var shouldScanBackend =
|
|
48
|
+
projectType === "fullstack" ||
|
|
49
|
+
projectType === "backend-only" ||
|
|
50
|
+
projectType === "mixed";
|
|
51
|
+
|
|
52
|
+
if (!shouldScanBackend) {
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// No live `app` instance exists at build time — pass null.
|
|
57
|
+
// All scanner functions read directly from the filesystem via cwd.
|
|
58
|
+
var endpoints = sdk.runBackendScanner(detected.backend, null, {}, cwd);
|
|
59
|
+
|
|
60
|
+
if (endpoints.length === 0) {
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
client
|
|
65
|
+
.registerEndpointsNow(endpoints)
|
|
66
|
+
.then(function () {
|
|
67
|
+
process.exit(0);
|
|
68
|
+
})
|
|
69
|
+
.catch(function (err) {
|
|
70
|
+
console.error(
|
|
71
|
+
"[BotVersion] Failed to report backend endpoints:",
|
|
72
|
+
err.message,
|
|
73
|
+
);
|
|
74
|
+
process.exit(0);
|
|
75
|
+
});
|
package/bin/scan-frontend.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
var path = require("path");
|
|
5
|
+
var fs = require("fs");
|
|
4
6
|
var scanner = require("../scanner");
|
|
5
7
|
var BotVersionClient = require("../client");
|
|
6
8
|
var sdk = require("../index");
|
|
7
9
|
|
|
10
|
+
// Auto-load env files from the customer's project, same precedence Next.js
|
|
11
|
+
// uses: .env first, then .env.local (which is allowed to override .env).
|
|
12
|
+
// dotenv.config() never overwrites a variable already set in process.env,
|
|
13
|
+
// so if the customer already exported the key in their shell/CI, that
|
|
14
|
+
// still takes priority over anything in these files.
|
|
15
|
+
(function loadEnvFiles() {
|
|
16
|
+
var dotenv;
|
|
17
|
+
try {
|
|
18
|
+
dotenv = require("dotenv");
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return; // dotenv not installed for some reason — skip silently
|
|
21
|
+
}
|
|
22
|
+
var cwd = process.cwd();
|
|
23
|
+
[".env", ".env.local"].forEach(function (file) {
|
|
24
|
+
var filePath = path.join(cwd, file);
|
|
25
|
+
if (fs.existsSync(filePath)) {
|
|
26
|
+
dotenv.config({ path: filePath });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
30
|
+
|
|
8
31
|
var apiKey = process.env.BOTVERSION_API_KEY;
|
|
9
32
|
var platformUrl =
|
|
10
|
-
process.env.BOTVERSION_PLATFORM_URL || "https://botversion.com";
|
|
33
|
+
process.env.BOTVERSION_PLATFORM_URL || "https://console.botversion.com";
|
|
11
34
|
|
|
12
35
|
if (!apiKey) {
|
|
13
36
|
console.error(
|
|
@@ -32,12 +55,6 @@ client
|
|
|
32
55
|
sdkLanguage: "javascript",
|
|
33
56
|
})
|
|
34
57
|
.then(function () {
|
|
35
|
-
console.log(
|
|
36
|
-
"[BotVersion] Reported " +
|
|
37
|
-
routePatterns.length +
|
|
38
|
-
" frontend routes. projectType=" +
|
|
39
|
-
projectType,
|
|
40
|
-
);
|
|
41
58
|
process.exit(0);
|
|
42
59
|
})
|
|
43
60
|
.catch(function (err) {
|
package/client.js
CHANGED
|
@@ -11,7 +11,7 @@ const url = require("url");
|
|
|
11
11
|
*/
|
|
12
12
|
function BotVersionClient(options) {
|
|
13
13
|
this.apiKey = options.apiKey;
|
|
14
|
-
this.platformUrl = options.platformUrl || "https://botversion.com";
|
|
14
|
+
this.platformUrl = options.platformUrl || "https://console.botversion.com";
|
|
15
15
|
this.debug = options.debug || false;
|
|
16
16
|
this.timeout = options.timeout || 30000;
|
|
17
17
|
|
package/index.js
CHANGED
|
@@ -421,7 +421,7 @@ var BotVersion = {
|
|
|
421
421
|
|
|
422
422
|
this._client = new BotVersionClient({
|
|
423
423
|
apiKey: options.apiKey,
|
|
424
|
-
platformUrl: options.platformUrl || "https://botversion.com",
|
|
424
|
+
platformUrl: options.platformUrl || "https://console.botversion.com",
|
|
425
425
|
debug: options.debug || false,
|
|
426
426
|
timeout: options.timeout || 30000,
|
|
427
427
|
});
|
|
@@ -504,3 +504,4 @@ module.exports.getEndpoints = BotVersion.getEndpoints;
|
|
|
504
504
|
module.exports.registerEndpoint = BotVersion.registerEndpoint;
|
|
505
505
|
module.exports.detectFrameworks = detectFrameworks;
|
|
506
506
|
module.exports.classifyInstallation = classifyInstallation;
|
|
507
|
+
module.exports.runBackendScanner = runBackendScanner;
|
package/interceptor.js
CHANGED
|
@@ -315,18 +315,36 @@ function attachNextJsInterceptor(client, options) {
|
|
|
315
315
|
return; // handled directly — don't pass through to the app
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
318
|
+
const DEV_ASSET_MARKERS = [
|
|
319
|
+
"/node_modules",
|
|
320
|
+
"/.svelte-kit",
|
|
321
|
+
"/@fs",
|
|
322
|
+
"/@vite",
|
|
323
|
+
"/@id",
|
|
324
|
+
"/debug-cors",
|
|
325
|
+
"/src/lib",
|
|
326
|
+
"/src/routes",
|
|
327
|
+
];
|
|
328
|
+
const STATIC_ASSET_EXT =
|
|
329
|
+
/\.(svelte|vue|css|scss|map|woff2?|ttf|eot|ico|png|jpe?g|gif|svg|webp|mjs)(\?.*)?$/i;
|
|
330
|
+
|
|
331
|
+
const shouldIgnore =
|
|
332
|
+
(options.exclude || [])
|
|
333
|
+
.concat([
|
|
334
|
+
"/health",
|
|
335
|
+
"/favicon.ico",
|
|
336
|
+
"/_next",
|
|
337
|
+
"/static",
|
|
338
|
+
"/public",
|
|
339
|
+
"/admin",
|
|
340
|
+
])
|
|
341
|
+
.some(function (p) {
|
|
342
|
+
return path.startsWith(p);
|
|
343
|
+
}) ||
|
|
344
|
+
DEV_ASSET_MARKERS.some(function (m) {
|
|
345
|
+
return path.includes(m);
|
|
346
|
+
}) ||
|
|
347
|
+
STATIC_ASSET_EXT.test(path);
|
|
330
348
|
|
|
331
349
|
const isApiPath = path.startsWith(options.apiPrefix || "/api");
|
|
332
350
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "botversion-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "BotVersion SDK — auto-detect and register your API endpoints",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"botversion-scan-frontend": "
|
|
7
|
+
"botversion-scan-frontend-routes": "bin/scan-frontend.js",
|
|
8
|
+
"botversion-scan-endpoints": "bin/scan-backend.js"
|
|
8
9
|
},
|
|
9
10
|
"keywords": [
|
|
10
11
|
"botversion",
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@babel/parser": "^7.29.3",
|
|
20
21
|
"@babel/traverse": "^7.29.0",
|
|
22
|
+
"dotenv": "^16.4.5",
|
|
21
23
|
"express": "^4.18.2"
|
|
22
24
|
}
|
|
23
25
|
}
|