@rajendra_7/securedev 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/README.md +30 -0
- package/dist/client.js +23 -0
- package/dist/index.js +22 -0
- package/dist/watcher.js +30 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# securedev
|
|
2
|
+
|
|
3
|
+
CLI agent for SecureDev real-time security scanning.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D securedev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx securedev watch
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Required environment variables:
|
|
18
|
+
|
|
19
|
+
- `SECUREDEV_API_KEY`
|
|
20
|
+
- `SECUREDEV_PROJECT_ID`
|
|
21
|
+
- `SECUREDEV_API_URL` (optional, defaults to `http://localhost:3000`)
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
SECUREDEV_API_KEY=sk_live_xxx \
|
|
27
|
+
SECUREDEV_PROJECT_ID=proj_xxx \
|
|
28
|
+
SECUREDEV_API_URL=http://localhost:3000 \
|
|
29
|
+
npx securedev watch
|
|
30
|
+
```
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
export const sendFileForScan = async (filePath, config) => {
|
|
3
|
+
const content = await readFile(filePath, "utf8");
|
|
4
|
+
const response = await fetch(`${config.apiUrl}/v1/scans`, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"content-type": "application/json",
|
|
8
|
+
authorization: `Bearer ${config.apiKey}`
|
|
9
|
+
},
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
project_id: config.projectId,
|
|
12
|
+
triggered_by: "agent",
|
|
13
|
+
files: [{ path: filePath, content }]
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
const text = await response.text();
|
|
18
|
+
throw new Error(`Scan failed (${response.status}): ${text}`);
|
|
19
|
+
}
|
|
20
|
+
const data = (await response.json());
|
|
21
|
+
const n = data.summary?.total_vulnerabilities ?? 0;
|
|
22
|
+
console.log(`✅ ${filePath} scanned - ${n} vulnerability${n === 1 ? "" : "ies"} found`);
|
|
23
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { startWatcher } from "./watcher.js";
|
|
5
|
+
const command = process.argv[2];
|
|
6
|
+
if (command !== "watch") {
|
|
7
|
+
console.error("Usage: securedev watch");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const apiKey = process.env.SECUREDEV_API_KEY;
|
|
11
|
+
const projectId = process.env.SECUREDEV_PROJECT_ID;
|
|
12
|
+
const apiUrl = process.env.SECUREDEV_API_URL || "http://localhost:3000";
|
|
13
|
+
if (!apiKey || !projectId) {
|
|
14
|
+
console.error("Missing SECUREDEV_API_KEY or SECUREDEV_PROJECT_ID");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
startWatcher({
|
|
18
|
+
apiKey,
|
|
19
|
+
projectId,
|
|
20
|
+
apiUrl,
|
|
21
|
+
cwd: process.cwd()
|
|
22
|
+
});
|
package/dist/watcher.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import chokidar from "chokidar";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { sendFileForScan } from "./client.js";
|
|
4
|
+
const codeExtension = /\.(ts|tsx|js|jsx|mjs|cjs|py|go|java|rb|php|rs)$/;
|
|
5
|
+
export const startWatcher = (config) => {
|
|
6
|
+
const watcher = chokidar.watch(config.cwd, {
|
|
7
|
+
ignored: [
|
|
8
|
+
/(^|[\\/])\../,
|
|
9
|
+
/node_modules/,
|
|
10
|
+
/dist/,
|
|
11
|
+
/build/,
|
|
12
|
+
/.git/
|
|
13
|
+
],
|
|
14
|
+
ignoreInitial: true,
|
|
15
|
+
persistent: true
|
|
16
|
+
});
|
|
17
|
+
watcher.on("change", async (absolutePath) => {
|
|
18
|
+
if (!codeExtension.test(absolutePath)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const relative = path.relative(config.cwd, absolutePath);
|
|
22
|
+
try {
|
|
23
|
+
await sendFileForScan(relative, config);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(`❌ ${relative} scan failed`, error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
console.log(`SecureDev watching ${config.cwd}`);
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rajendra_7/securedev",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"securedev": "dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "node --import tsx src/index.ts watch",
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
17
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"chokidar": "^4.0.1",
|
|
21
|
+
"dotenv": "^16.4.5"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.9.0",
|
|
25
|
+
"ts-node": "^10.9.2",
|
|
26
|
+
"tsx": "^4.21.0",
|
|
27
|
+
"typescript": "^5.6.3"
|
|
28
|
+
}
|
|
29
|
+
}
|