moyan-security-audit 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.
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/audit.d.ts +2 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +77 -0
- package/dist/audit.js.map +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +56 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Moyan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# moyan-security-audit
|
|
2
|
+
|
|
3
|
+
Agent-native security audit SDK for Node.js — send source code to the Moyan audit engine and receive structured vulnerability reports with PMI trust scoring.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install moyan-security-audit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
|
|
13
|
+
Set your API key via one of:
|
|
14
|
+
|
|
15
|
+
1. Environment variable:
|
|
16
|
+
```bash
|
|
17
|
+
export MOYAN_API_KEY="your-api-key"
|
|
18
|
+
```
|
|
19
|
+
2. Config file `~/.moyan/config.json`:
|
|
20
|
+
```json
|
|
21
|
+
{ "apiKey": "your-api-key" }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
If neither is set, the SDK throws a descriptive error.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### CommonJS
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const { audit } = require('moyan-security-audit');
|
|
32
|
+
|
|
33
|
+
async function main() {
|
|
34
|
+
const result = await audit({
|
|
35
|
+
code: 'SELECT * FROM users WHERE id = ' + userId,
|
|
36
|
+
language: 'sql',
|
|
37
|
+
auditLevel: 'L2',
|
|
38
|
+
timeout: 30000,
|
|
39
|
+
retries: 2,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
console.log(`PMI Score: ${result.pmi_score}`);
|
|
43
|
+
console.log(`Severity: ${result.severity}`);
|
|
44
|
+
console.log(`Violations: ${result.violations.length}`);
|
|
45
|
+
console.log(`Recommendation: ${result.recommendation}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### ESM / TypeScript
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { audit, AuditOptions, AuditResult } from 'moyan-security-audit';
|
|
55
|
+
|
|
56
|
+
const opts: AuditOptions = {
|
|
57
|
+
code: `const query = "SELECT * FROM users WHERE id = " + userId;`,
|
|
58
|
+
language: 'javascript',
|
|
59
|
+
auditLevel: 'L1',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const result: AuditResult = await audit(opts);
|
|
63
|
+
console.log(result);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
### `audit(options: AuditOptions): Promise<AuditResult>`
|
|
69
|
+
|
|
70
|
+
| Parameter | Type | Required | Default | Description |
|
|
71
|
+
|---|---|---|---|---|
|
|
72
|
+
| `code` | `string` | Yes | — | Source code to audit |
|
|
73
|
+
| `language` | `AuditLanguage` | Yes | — | One of: sql, python, javascript, typescript, java, go, rust, solidity |
|
|
74
|
+
| `auditLevel` | `AuditLevel` | No | `'L1'` | L1 (quick scan), L2 (deep analysis), L3 (full audit) |
|
|
75
|
+
| `timeout` | `number` | No | `30000` | Request timeout in ms |
|
|
76
|
+
| `retries` | `number` | No | `2` | Retry count with exponential backoff (1s, 2s, 4s, ...) |
|
|
77
|
+
|
|
78
|
+
### AuditResult
|
|
79
|
+
|
|
80
|
+
| Field | Type | Description |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `audit_id` | `string` | Unique identifier for this audit run |
|
|
83
|
+
| `pmi_score` | `number` | PMI trust score (0-100) |
|
|
84
|
+
| `severity` | `'pass' \| 'warn' \| 'fail'` | Overall verdict |
|
|
85
|
+
| `violations` | `AuditViolation[]` | Detected rule violations |
|
|
86
|
+
| `recommendation` | `string` | High-level remediation guidance |
|
|
87
|
+
|
|
88
|
+
### AuditViolation
|
|
89
|
+
|
|
90
|
+
| Field | Type | Description |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `rule_id` | `string` | Rule identifier (e.g. SQLI-001) |
|
|
93
|
+
| `severity` | `'critical' \| 'high' \| 'medium' \| 'low' \| 'info'` | Violation severity |
|
|
94
|
+
| `message` | `string` | Human-readable description |
|
|
95
|
+
| `line` | `number` | Source line number (1-based) |
|
|
96
|
+
| `snippet` | `string` | Violating code snippet |
|
|
97
|
+
| `fix` | `string` | Suggested remediation |
|
|
98
|
+
|
|
99
|
+
## API Endpoint
|
|
100
|
+
|
|
101
|
+
All audit requests are sent to:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
POST https://sixu-ai.net.cn/api/v1/audit
|
|
105
|
+
Authorization: Bearer <MOYAN_API_KEY>
|
|
106
|
+
Content-Type: application/json
|
|
107
|
+
|
|
108
|
+
{ "code": "...", "language": "sql", "audit_level": "L2" }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA2BzD;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA+DvE"}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.audit = audit;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const API_BASE = 'https://sixu-ai.net.cn/api/v1/audit';
|
|
12
|
+
const optionsSchema = zod_1.z.object({
|
|
13
|
+
code: zod_1.z.string().min(1, 'code must be non-empty'),
|
|
14
|
+
language: zod_1.z.enum(['sql', 'python', 'javascript', 'typescript', 'java', 'go', 'rust', 'solidity']),
|
|
15
|
+
auditLevel: zod_1.z.enum(['L1', 'L2', 'L3']).optional().default('L1'),
|
|
16
|
+
timeout: zod_1.z.number().int().positive().optional().default(30000),
|
|
17
|
+
retries: zod_1.z.number().int().min(0).max(5).optional().default(2),
|
|
18
|
+
});
|
|
19
|
+
function toAuditResult(raw) {
|
|
20
|
+
return {
|
|
21
|
+
audit_id: String(raw.audit_id ?? ''),
|
|
22
|
+
pmi_score: Number(raw.pmi_score ?? 0),
|
|
23
|
+
severity: (['pass', 'warn', 'fail'].includes(String(raw.severity)) ? String(raw.severity) : 'warn'),
|
|
24
|
+
violations: Array.isArray(raw.violations)
|
|
25
|
+
? raw.violations.map((v) => ({
|
|
26
|
+
rule_id: String(v.rule_id ?? ''),
|
|
27
|
+
severity: (['critical', 'high', 'medium', 'low', 'info'].includes(String(v.severity)) ? String(v.severity) : 'info'),
|
|
28
|
+
message: String(v.message ?? ''),
|
|
29
|
+
line: Number(v.line ?? 0),
|
|
30
|
+
snippet: String(v.snippet ?? ''),
|
|
31
|
+
fix: String(v.fix ?? ''),
|
|
32
|
+
}))
|
|
33
|
+
: [],
|
|
34
|
+
recommendation: String(raw.recommendation ?? ''),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async function audit(options) {
|
|
38
|
+
const opts = optionsSchema.parse(options);
|
|
39
|
+
const apiKey = (0, config_1.getApiKey)();
|
|
40
|
+
const maxRetries = opts.retries;
|
|
41
|
+
let lastError = null;
|
|
42
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await axios_1.default.post(API_BASE, {
|
|
45
|
+
code: opts.code,
|
|
46
|
+
language: opts.language,
|
|
47
|
+
audit_level: opts.auditLevel,
|
|
48
|
+
}, {
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
Authorization: `Bearer ${apiKey}`,
|
|
52
|
+
},
|
|
53
|
+
timeout: opts.timeout,
|
|
54
|
+
});
|
|
55
|
+
return toAuditResult(response.data);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
59
|
+
if (attempt < maxRetries) {
|
|
60
|
+
const backoffMs = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s...
|
|
61
|
+
await (0, utils_1.sleep)(backoffMs);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (axios_1.default.isAxiosError(err)) {
|
|
65
|
+
if (err.code === 'ECONNABORTED') {
|
|
66
|
+
throw new Error(`Audit request timed out after ${opts.timeout}ms.`);
|
|
67
|
+
}
|
|
68
|
+
if (err.response) {
|
|
69
|
+
throw new Error(`Audit API returned status ${err.response.status}: ${JSON.stringify(err.response.data)}`);
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Network error contacting audit API: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
throw lastError;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw lastError ?? new Error('Audit failed after retries.');
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,sBA+DC;AAnGD,+CAA0C;AAC1C,6BAAwB;AACxB,qCAAqD;AACrD,mCAAiD;AAGjD,4CAA4C;AAE5C,MAAM,mBAAmB,GAAG,OAAC,CAAC,IAAI,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AI,GAAG,CAAC,OAAO,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CACb,kCAAkC,uBAAc,kCAAkC,CACnF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getApiKey(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAwBlC;AAED,eAAO,MAAM,cAAc,wCAAwC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getApiKey = getApiKey;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
function getApiKey() {
|
|
41
|
+
const envKey = process.env.MOYAN_API_KEY;
|
|
42
|
+
if (envKey && envKey.trim().length > 0)
|
|
43
|
+
return envKey.trim();
|
|
44
|
+
const configPath = path.join(os.homedir(), '.moyan', 'config.json');
|
|
45
|
+
try {
|
|
46
|
+
if (fs.existsSync(configPath)) {
|
|
47
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
48
|
+
if (config.apiKey && typeof config.apiKey === 'string' && config.apiKey.trim().length > 0) {
|
|
49
|
+
return config.apiKey.trim();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch { /* fall through */ }
|
|
54
|
+
throw new Error('MOYAN_API_KEY not found. Set the MOYAN_API_KEY environment variable or create ' +
|
|
55
|
+
configPath + ' with {"apiKey": "your-key"}.');
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,8BAwBC;AAjCD,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AAEzB;;;;GAIG;AACH,SAAgB,SAAS;IACvB,YAAY;IACZ,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IACzC,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAED,YAAY;IACZ,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/B,IAAI,MAAM,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACtF,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,mBAAmB;IACrB,CAAC;IAED,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;AACJ,CAAC;AAEY,QAAA,cAAc,GAAG,qCAAqC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.audit = void 0;
|
|
18
|
+
var audit_1 = require("./audit");
|
|
19
|
+
Object.defineProperty(exports, "audit", { enumerable: true, get: function () { return audit_1.audit; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,0CAAwB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AuditLanguage = 'sql' | 'python' | 'javascript' | 'typescript' | 'java' | 'go' | 'rust' | 'solidity';
|
|
2
|
+
export type AuditLevel = 'L1' | 'L2' | 'L3';
|
|
3
|
+
export interface AuditOptions {
|
|
4
|
+
code: string;
|
|
5
|
+
language: AuditLanguage;
|
|
6
|
+
auditLevel?: AuditLevel;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
retries?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AuditViolation {
|
|
11
|
+
rule_id: string;
|
|
12
|
+
severity: 'critical' | 'high' | 'medium' | 'low' | 'info';
|
|
13
|
+
message: string;
|
|
14
|
+
line: number;
|
|
15
|
+
snippet: string;
|
|
16
|
+
fix: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AuditResult {
|
|
19
|
+
audit_id: string;
|
|
20
|
+
pmi_score: number;
|
|
21
|
+
severity: 'pass' | 'warn' | 'fail';
|
|
22
|
+
violations: AuditViolation[];
|
|
23
|
+
recommendation: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,QAAQ,GACR,YAAY,GACZ,YAAY,GACZ,MAAM,GACN,IAAI,GACJ,MAAM,GACN,UAAU,CAAC;AAEf,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,CAAC;IACxB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAkBjF;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAGA,sBAGC;AAKD,kCAkBC;AAKD,8BAoBC;AAtDD;;GAEG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;IACxD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EA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AED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAC7D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "moyan-security-audit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Agent-native security audit SDK — audit(code, language, auditLevel) → { audit_id, pmi_score, severity, violations, recommendation }",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist/"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": ["security","audit","code-review","agent","sql-injection","sast","moyan","sixu"],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Sixu AI",
|
|
16
|
+
"repository": { "type": "git", "url": "https://github.com/sixu-ai/moyan-security-audit-js" },
|
|
17
|
+
"dependencies": { "axios": "^1.7.0", "zod": "^3.23.0" },
|
|
18
|
+
"devDependencies": { "typescript": "^5.5.0", "@types/node": "^20.0.0", "jest": "^29.0.0", "ts-jest": "^29.0.0", "@types/jest": "^29.0.0" }
|
|
19
|
+
}
|